<pre class='metadata'>
Title: CSS Ruby Annotation Layout Module Level 1
Shortname: css-ruby
Level: 1
Status: ED
Work Status: Revising
Group: csswg
ED: https://drafts.csswg.org/css-ruby-1/
TR: https://www.w3.org/TR/css-ruby-1/
Test Suite: https://w3c.github.io/i18n-tests/results/css-ruby
Previous Version: https://www.w3.org/TR/2021/WD-css-ruby-1-20211202/
Previous Version: https://www.w3.org/TR/2021/WD-css-ruby-1-20210310/
Previous Version: https://www.w3.org/TR/2020/WD-css-ruby-1-20200429/
Previous Version: https://www.w3.org/TR/2014/WD-css-ruby-1-20140805/
Previous Version: https://www.w3.org/TR/2013/WD-css3-ruby-20130919/
Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Koji Ishii, Google, kojiishi@gmail.com, w3cid 45369
Editor: Xidorn Quan, Mozilla https://www.mozilla.org/, https://www.upsuper.org/, w3cid 73936
Editor: Florian Rivoal, Invited Expert, https://florian.rivoal.net/, w3cid 43241
Abstract: “Ruby”, a form of interlinear annotation, are short runs of text alongside the base text.
Abstract: They are typically used in East Asian documents to indicate pronunciation or to provide a short annotation.
Abstract: This module describes the rendering model and formatting controls related to displaying ruby annotations in CSS.
</pre>
<pre class=link-defaults>
spec:css-text-3; type:dfn; text:character
spec:css-box-4; type:dfn; text:content area
</pre>
<style>
  /* ASCII diagram colors */
  .base { color: blue; }
  .annot { color: red; }
  .column { color: gray; }
  .flagtxt1 { color: green; }
  .flagtxt2 { color: #ae4a00; }
  .flagbg1 { background: green; opacity: 0.3; }
  .flagbg2 { background: orange; opacity: 0.3; }
</style>

<h2 id="intro">
Introduction</h2>

<h3 id="ruby-def">
What is ruby?</h3>

	<em>This subsection is not normative.</em>

	<dfn export>Ruby</dfn> is the commonly-used name for a run of text
	that appears alongside another run of text (referred to as the “base”)
	and serves as an annotation or a pronunciation guide associated with that run of text.

	<figure>
		<img src="images/ruby-context.png"
		     alt="Hiragana ruby annotations above each kanji in Japanese text">
		<figcaption>A run of Japanese text with phonetic ruby annotations indicating the pronunciation of each ideograph.</figcaption>
	</figure>

	The following figures show two examples of Ruby,
	a simple case and one with more complicated structure.

	<div class="example">
		In this example, a single annotation is used to annotate a base text
		consisting of multiple characters.
		<div class="figure">
			<img src="images/licence.png"
			     alt="Example of ruby applied on top of a Japanese expression">
			<p class="caption">Example of ruby used in Japanese (simple case)
		</div>

		In Japanese typography, this case is sometimes called
		taigo ruby (Japanese: <span lang="ja">対語ルビ</span>, i.e. per-word ruby) or group-ruby,
		because the annotation as a whole is associated
		with multi-character word (as a whole).
	</div>

	<div class="example">
		In this second example,
		two levels of annotations are attached to the base text:
		the hiragana characters on top refer to the pronunciation of each of the base kanji characters,
		while the words “Keio” and “University” on the bottom are give the English translation.
		<div class="figure">
			<img src="images/ruby-univ.gif"
			     alt="Example showing complex ruby with annotation text over and under the base characters">
			<p class="caption">Complex ruby with annotation text over and under the base characters
		</div>

		Notice that to reflect the correct association
		of hiragana characters and their corresponding Kanji base characters,
		the spacing within the base-level text is adjusted.
		(This happens around the fourth Kanji character in the figure above,
		 which has a three-character phonetic gloss.)
		To avoid variable spacing of the base text in the example above,
		the hiragana annotations can be styled as a [=merged annotation=],
		which will look more like the group-ruby example earlier.
		However because the base-annotation [=pairings=] are recorded in the ruby structure,
		if the text breaks across lines, the annotation characters will stay
		correctly paired with their respective base characters.
	</div>

	In HTML, ruby structure and markup to represent it is described
	in the Ruby Markup Extension specification.
	This module describes the CSS rendering model
	and formatting controls relevant to ruby layout of such markup.

	A more in-depth introduction to [=Ruby=] and its formatting
	can be found in the “What is Ruby“ article [[QA-RUBY]].
	Extensive information about the main ways [=ruby=] has traditionally been formatted in Japanese
	can be found in JIS X-4051 [[JIS4051]] (in Japanese)
	and in <a href="https://www.w3.org/TR/jlreq/#ruby_and_emphasis_dots">“Ruby and Emphasis Dots”</a> in <cite>Requirements for Japanese Text Layout</cite> [[JLREQ]] (in English and Japanese);
	<cite>Rules for Simple Placement of Japanese Ruby</cite> [[SIMPLE-RUBY]]
	also describes (in English) one possible approach for Japanese ruby formatting.
	<a href="https://www.w3.org/TR/clreq/#interlinear_annotations">“Interlinear annotations”</a> in <cite>Requirements for Chinese Text Layout</cite> [[CLREQ]]
	describes the related practices for Chinese typography (in Chinese and English).

<h3 id="placement">
Module interactions</h3>

	This module extends the inline box model of CSS Level 2 [[!CSS2]]
	to support ruby.

	None of the properties in this module apply to the ''::first-line'' or
	''::first-letter'' pseudo-elements;
	however 'ruby-position' can inherit through ''::first-line'' to affect
	ruby annotations on the first line.

<h3 id="values">
Value Definitions</h3>

	This specification follows the <a href="https://www.w3.org/TR/CSS2/about.html#property-defs">CSS property definition conventions</a> from [[!CSS2]]
	using the <a href="https://www.w3.org/TR/css-values-3/#value-defs">value definition syntax</a> from [[!CSS-VALUES-3]].
	Value types not defined in this specification are defined in CSS Values &amp; Units [[!CSS-VALUES-3]].
	Combination with other CSS modules may expand the definitions of these value types.

	In addition to the property-specific values listed in their definitions,
	all properties defined in this specification
	also accept the [=CSS-wide keywords=] keywords as their property value.
	For readability they have not been repeated explicitly.

<h3 id="diagram-conventions">
Diagram conventions</h3>

	<em>This subsection is not normative.</em>

	Many typographical conventions in East Asian typography depend
	on whether the character rendered is wide (CJK) or narrow (non-CJK).
	There are a number of illustrations in this document
	for which the following legend is used:

	<dl>
		<dt><img alt="Symbolic wide-cell glyph representation" width="39" height="39" src="images/fullwidth.gif">
		<dd>
			Wide-cell glyph (e.g. Han) that is the <var>n</var>th character in the text sequence.
			They are typically sized to 50% when used as annotations.
		<dt><img alt="Symbolic narrow-cell glyph representation" width="19" height="39" src="images/halfwidth.gif">
		<dd>Narrow-cell glyph (e.g. Roman) which is the <var>n</var>th glyph in the text sequence.
	</dl>

	The orientation which the above symbols assume in the diagrams
	corresponds to the orientation that the glyphs they represent
	are intended to assume when rendered by the user agent.
	Spacing between these characters in the diagrams is incidental,
	unless intentionally changed to make a point.

<h2 id="ruby-model">
Ruby Box Model</h2>

	The CSS ruby model is based on
	the <a href="https://www.w3.org/TR/html5/text-level-semantics.html#the-ruby-element">W3C HTML5 Ruby Markup</a> model
	and the <a href="https://www.w3.org/TR/ruby/">XHTML Ruby Annotation Recommendation</a> [[RUBY]].
	In this model, a ruby structure consists of
	one or more [=ruby base=] elements representing the base (annotated) text,
	associated with one or more levels of [=ruby annotation=] elements representing the annotations.
	The structure of ruby is similar to that of a table:
	there are “rows” (the [=base text level=], each [=annotation level=])
	and “[=columns=]” (each [=ruby base=] and its corresponding [=ruby annotations=]).

	<figure>
		<img src="images/ruby-boxes-simple.png"
		     alt="Ruby structure arranged as a table,
		          the first “column” containing 上 in a base box with じょう centered below in an annotation box
		          and the second “column” containing 手 in a separate base box with ず centered below in another annotation box.">
		<figcaption>The Japanese compound word “<span lang=ja>上手</span>” annotated with its pronunciation “<span lang=ja>じょうず</span>”. Each syllable is associated individually with its base character.</figcaption>
	</figure>

	Sets of consecutive bases and their consecutive annotations are grouped together into [=ruby segments=].
	Within a [=ruby segment=], a [=ruby annotation=] may span multiple [=ruby bases=].

	<figure>
		<img src="images/ruby-boxes-complex.png"
		     alt="Ruby structure arranged as a table,
		          the first “column” containing 旧 in a base box with jiù centered above in an annotation box,
		          the second “column” containing 金 in a base box with jīn centered above in an annotation box,
		          the third “column” containing 山 in a base box with .shān centered above it in an annotation box,
		          and the name San Francisco centered below the entire phrase in an annotation box that spans all three “columns”.">
		<figcaption>The Chinese city name “<span lang="zh-Hans">旧金山</span>” annotated with its pronunciation in Pinyin “<span lang="zh-Latn-pinyin">jiùjīnshān</span>” and its English name “San Francisco”. Each Pinyin syllable is associated individually with its base character, however the English name is associated with the name as a whole.</figcaption>
	</figure>

	Note: In HTML, a single <code>&lt;ruby&gt;</code> element may contain multiple [=ruby segments=].
	(In the XHTML Ruby model, a single <code>&lt;ruby&gt;</code> element can only contain one [=ruby segment=].)

<h3 id="ruby-display">
Ruby-specific 'display' Values</h3>

	For document languages (such as XML applications) that do not have pre-defined ruby elements,
	authors must map document language elements to ruby elements;
	this is done with the 'display' property.

	<div class="informative">
		<pre class=propdef partial>
		Name: display
		New values: ruby | ruby-base | ruby-text | ruby-base-container | ruby-text-container
		</pre>
	</div>

	The following new 'display' values assign ruby layout roles to an arbitrary element:

	<dl dfn-type=value export dfn-for=display>
		<dt><dfn>ruby</dfn>
		<dd>
			Specifies that an element generates a <dfn dfn for lt="ruby container | ruby container box">ruby container box</dfn>.
			(Corresponds to HTML/XHTML <code>&lt;ruby&gt;</code> elements.)
		<dt><dfn>ruby-base</dfn>
		<dd>
			Specifies that an element generates a <dfn dfn for lt="ruby base box | ruby base | base | base box">ruby base box</dfn>.
			(Corresponds to HTML/XHTML <code>&lt;rb&gt;</code> elements.)
		<dt><dfn>ruby-text</dfn>
		<dd>
			Specifies that an element generates a <dfn dfn for lt="ruby annotation box | ruby annotation | annotation | annotation box">ruby annotation box</dfn>.
			(Corresponds to HTML/XHTML <code>&lt;rt&gt;</code> elements.)
		<dt><dfn>ruby-base-container</dfn>
		<dd>
			Specifies that an element generates a <dfn dfn for lt="ruby base container box | ruby base container" local-lt="base container">ruby base container box</dfn>.
			(Corresponds to XHTML <code>&lt;rbc&gt;</code> elements; generated as an anonymous box in HTML.)
		<dt><dfn>ruby-text-container</dfn>
		<dd>
			Specifies that an element generates a <dfn dfn for lt="ruby annotation container box | ruby annotation container" local-lt="annotation container">ruby annotation container box</dfn>.
			(Corresponds to HTML/XHTML <code>&lt;rtc&gt;</code> elements.)
	</dl>

	<p class="advisement">Authors using a language (such as HTML)
	that supports dedicated ruby markup
	should use that markup rather than
	styling arbitrary elements (like <code>&lt;span&gt;</code>)
	with ruby 'display' values.
	Using the correct markup ensures that screen readers
	and non-CSS renderers can interpret the ruby structures.

	Note: [=Replaced elements=] with a 'display' value of
	''ruby-base'',
	''ruby-text'',
	''ruby-base-container'',
	and ''ruby-text-container''
	are treated as [=inline-level boxes=],
	as per [[css-display-3#layout-specific-display]];
	[=replaced elements=] with a 'display' value of ''ruby'' or ''inline ruby''
	behave according to their [=outer display type=],
	as per [[css-display-3#outer-role]].
	(See also [[#block-ruby]].)

<h4 id="formatting-context">
The Ruby Formatting Context</h4>

	[=Ruby containers=] are non-atomic [=inline-level=] boxes.
	Like regular [=inline boxes=] (see [[css-inline-3#model]]),
	they break across lines,
	and their [=containing block=] is the nearest [=block container=] ancestor.
	And just as the contents of an [=inline box=]
	participate in the same [=inline formatting context=] that contains the [=inline box=] itself,
	a [=ruby container=] and its base-level contents
	participate in the same [=inline formatting context=] that contains the [=ruby container=] itself.

	However [=ruby containers=] also establish a <dfn export>ruby formatting context</dfn>
	that builds further structure around their segment of the [=inline formatting context=]
	in order to host their annotations.
	<span class=note>Note: this [=formatting context=] is <em>not</em> an [=independent formatting context=].</span>
	[=Ruby bases=], [=ruby annotations=], [=ruby base containers=], and [=ruby annotation containers=]
	are <dfn export lt="internal ruby boxes|internal ruby display types">internal ruby boxes</dfn>:
	like [=internal table elements=],
	they have specific roles in ruby layout,
	and participate in their [=ruby container=]’s [=ruby formatting context=].
	In addition to their role in the [=ruby formatting context=],
	[=ruby bases=] simultaneously participate
	in the same base-level [=inline formatting context=] as the [=ruby container=],
	while [=ruby annotations=] participate
	in separate annotation-level [=inline formatting contexts=]
	established by the [=ruby container=].

	As with the contents of [=inline boxes=],
	the [=containing block=] for the contents of a [=ruby container=] (and all its [=internal ruby boxes=])
	is the [=containing block=] of the [=ruby container=].
	So floats, for example, are trapped by the [=ruby container=]’s [=containing block=],
	not any of the ruby box types.

<h4 id="block-ruby">
Non-Inline Ruby</h4>

	If an element has an [=inner display type=] of ''ruby''
	and an [=outer display type=] other than ''display/inline'',
	then it generates two boxes:
	a principal box of the required [=outer display type=] type,
	and an inline-level [=ruby container=].
	All properties specified on the element apply to the principal box
	(and if inheritable, inherit to the [=ruby container box=]).
	This allows styling the element as a block,
	while correctly maintaining the internal ruby structure.

	Note: Absolute positioning or floating an element causes its 'display' value
	to compute to a block-level equivalent. (See [[!CSS-DISPLAY-3]] or [[!CSS2]] section 9.7.)
	For the [=internal ruby display types=],
	this causes their 'display' value to compute to ''display/block''.

<h3 id="box-fixup">
Anonymous Ruby Box Generation</h3>

	The CSS model does not require that the document language
	include elements that correspond to each of these components.
	Missing parts of the structure are implied through the anonymous box generation rules
	<a href="https://www.w3.org/TR/CSS2/tables.html#anonymous-boxes">similar to those used to normalize tables</a>. [[!CSS2]]

	<ol>
		<li id="anon-gen-inlinize"><strong>[=Inlinify=] block-level boxes:</strong>
			Any [=in-flow=] boxes directly contained by a
			[=ruby container=],
			[=ruby base container=],
			[=ruby annotation container=],
			[=ruby base box=],
			or [=ruby annotation box=]
			are “[=inlinified=]” per [[!CSS-DISPLAY-3]]),
			and their 'display' value computed accordingly,
			so that they contain only inline-level content.
			For example,
			the 'display' property of an in-flow element with ''display: block''
			parented by an element with ''display: ruby-text''
			computes to ''inline-block''.

		<li id="anon-gen-anon-ruby"><strong>Generate anonymous ruby containers:</strong>
			Any <a href="https://www.w3.org/TR/CSS2/tables.html#anonymous-boxes">consecutive</a> sequence of
			improperly-contained
			[=ruby base containers=],
			[=ruby annotation containers=],
			[=ruby bases=],
			and/or
			[=ruby annotations=]
			(and any intervening [=white space=])
			is wrapped in an anonymous [=ruby container=].
			For the purpose of this step:
			<ul>
				<li>an improperly-contained [=ruby base=] is one not parented by a [=ruby base container=] or [=ruby container=]
				<li>an improperly-contained [=ruby annotation=] is one not parented by a [=ruby annotation container=] or [=ruby container=]
				<li>
					an improperly-contained [=ruby base container=] or [=ruby annotation container=]
					is one not parented by a [=ruby container=]
			</ul>

		<li id="anon-gen-bare-inlines"><strong>Wrap misparented inline-level content:</strong>
			Any consecutive sequence of text and inline-level boxes
			directly parented by a [=ruby container=] or [=ruby base container=]
			is wrapped in an anonymous [=ruby base=].
			Similarly, any consecutive sequence of text and inline-level boxes
			directly parented by a [=ruby annotation container=]
			is wrapped in an anonymous [=ruby annotation=].
			(For this purpose, misparented [=internal table elements=]
			are treated as [=inline-level content=]
			since, being parented by ruby boxes,
			they will be ultimately wrapped by an [=inline-level=] [=table wrapper box=].)

			However, if an anonymous box so constructed contains only [=white space=],
			it is considered <dfn>intra-ruby white space</dfn>
			and is either discarded
			or preserved
			as described below.

		<li id="anon-gen-trim-space"><strong>Trim leading/trailing white space:</strong>
			Any [=intra-ruby white space=]
			that is not the sole [=in-flow=] child of its parent
			and is the first or last [=in-flow=] child of
			a [=ruby container=], [=ruby annotation container=], or [=ruby base container=]
			is removed, as if it had ''display: none''

		<li id="anon-gen-discard-space"><strong>Remove inter-level white space:</strong>
			Any [=intra-ruby white space=]
			whose immediately adjacent [=in-flow=] siblings match one of the patterns below
			is <dfn noexport>inter-level white space</dfn>
			and is removed, as if it had ''display: none''.
			<table class="data">
			<thead>
				<tr><th>Previous box
				    <th>Next box
			<tbody>
				<tr><td>any
				    <td>[=ruby annotation container=]
				<tr><td>not [=ruby annotation=]
				    <td>[=ruby annotation=]
<!--
				<tr><td>[=ruby base=] or [=ruby base container=]
				    <td>[=ruby annotation=] or [=ruby annotation container=]
				<tr><td>[=ruby annotation container=]
				    <td>[=ruby annotation container=]
				<tr><td>[=ruby annotation=]
				    <td>[=ruby annotation container=]
				<tr><td>[=ruby annotation container=]
				    <td>[=ruby annotation=]
-->
			</table>

		<li id="anon-gen-interpret-space"><strong>Interpret intra-level white space:</strong>
			Any [=intra-ruby white space=] box
			whose immediately adjacent [=in-flow=] siblings match one of the patterns below
			is assigned the box type and subtype defined in the table below:
			<table class="data">
			<colgroup span=2></colgroup>
			<colgroup span=2></colgroup>
			<thead>
				<tr><th>Previous box
				    <th>Next box
				    <th>Box type
				    <th>Subtype
			<tbody>
				<tr><td>[=ruby base=]
				    <td>[=ruby base=]
				    <td>[=ruby base=]
				    <td><dfn>inter-base white space</dfn>
				<tr><td>[=ruby annotation=]
				    <td>[=ruby annotation=]
				    <td>[=ruby annotation=]
				    <td><dfn>inter-annotation white space</dfn>
				<tr><td>[=ruby annotation=] or [=ruby annotation container=]
				    <td>[=ruby base=] or [=ruby base container=]
				    <td rowspan=3>[=ruby base=]
				    <td rowspan=3><dfn>inter-segment white space</dfn>
				<tr><td>[=ruby base=] or [=ruby base container=]
				    <td>[=ruby base container=]
				<tr><td>[=ruby base container=]
				    <td>[=ruby base=] or [=ruby base container=]
			</table>
			The <dfn>intra-level white space</dfn> boxes defined above
			are treated specially for [=pairing=] and layout.
			See below.

		<li id="anon-gen-unbreak"><strong>Suppress line breaks:</strong>
			Convert all forced line breaks inside [=ruby annotations=] (regardless of 'white-space' value)
			as defined for collapsible segment breaks in <a href="https://www.w3.org/TR/css-text-3/#line-break-transform">CSS Text Level 3 &sect; 4.1.2</a>.

			Issue: The goal of this is to simplify the layout model by suppressing any line breaks within ruby annotations.
			Alternatively we could try to define some kind of acceptable behavior for them.

		<li id="anon-gen-anon-containers"><strong>Generate anonymous level containers:</strong>
			Any consecutive sequence of [=ruby bases=] and [=inter-base white space=]
			(and not [=inter-segment white space=])
			not parented by a [=ruby base container=]
			is wrapped in an anonymous [=ruby base container=].
			Similarly, any consecutive sequence of [=ruby annotations=] and [=inter-annotation white space=]
			not parented by a [=ruby annotation container=]
			is wrapped in an anonymous [=ruby annotation container=].
	</ol>

	Once all ruby layout structures are properly parented,
	the UA can start to associate bases with their annotations.

	Note: The UA is not required to create any of these anonymous boxes
	(or the anonymous empty [=intra-level white space=] boxes in [[#ruby-pairing]])
	in its internal structures,
	as long as [=pairing=] and layout behaves as if they existed.

	<div class="example">
		The following markup diagram representing the various boxes
		shows where [=intra-ruby white space=] is preserved or discarded:
		<xmp highlight=html style="white-space: normal; overflow-wrap: break-word">
			<ruby>×<rbc>×<rb></rb>⬕<rb></rb>×</rbc>☒<rtc>×<rt></rt>⬔<rt></rt>×</rtc>◼<rbc>×<rb></rb>…</rtc>×</ruby>
		</xmp>
		where
		* × represents <a href="#anon-gen-trim-space">discarded leading/trailing white space</a>
		* ☒ represents <a href="#anon-gen-discard-space">discarded inter-level white space</a>
		* ⬕ represents [=inter-base white space=]
		* ⬔ represents [=inter-annotation white space=]
		* ◼ represents [=inter-segment white space=]
	</div>

<h3 id="ruby-pairing">
Annotation Pairing</h3>

	Annotation <dfn>pairing</dfn> is the process of associating
	[=ruby annotations=] with [=ruby bases=].
	Each [=ruby annotation=] is associated with one or more [=ruby bases=],
	and is said to <dfn>span</dfn> those bases.
	(A [=ruby annotation=] that [=spans=] multiple bases is called
	a <dfn>spanning annotation</dfn>.)

	A [=ruby base=] can be associated with
	only one [=ruby annotation=] per [=annotation level=].
	However, if there are multiple [=annotation levels=],
	it can be associated with multiple [=ruby annotations=].

	Once [=pairing=] is complete, <dfn local-lt=column>ruby columns</dfn> are defined,
	each represented by a single [=ruby base=]
	and one [=ruby annotation=] (possibly an empty, anonymous one)
	from each [=interlinear=] [=annotation level=] in its [=ruby segment=].

<h4 id="segment-pairing">
Segment Pairing and Annotation Levels</h4>

	A ruby structure is divided into <dfn>ruby segments</dfn>,
	each consisting of a single [=ruby base container=]
	followed by one or more [=ruby annotation containers=].
	Each [=ruby annotation container=] in a [=ruby segment=]
	represents one <dfn lt="annotation level | level">level</dfn> of annotation for the base text:
	the first one represents the first level of annotation,
	the second one represents the second level of annotation,
	and so on.
	The [=ruby base container=] represents the <dfn lt="base level | base text level">base level</dfn>.
	The [=ruby base container=] in each segment is thus paired
	with each of the [=ruby annotation containers=] in that segment.

	In order to handle degenerate cases, some empty anonymous containers are assumed:
	<ul>
		<li>
			If the first child of a [=ruby container=] is a [=ruby annotation container=],
			an anonymous, empty [=ruby base container=] is assumed to exist before it.
		<li>
			Similarly, if the [=ruby container=] contains consecutive [=ruby base containers=],
			anonymous, empty [=ruby annotation containers=] are assumed to exist between them.
	</ul>

	[=Inter-segment white space=] is effectively a [=ruby segment=] of its own.

<h4 id="base-annotation-pairing">
Unit Pairing and Spanning Annotations</h4>

	Within a [=ruby segment=],
	each [=ruby base=] in the [=ruby base container=]
	is paired with one [=ruby annotation=]
	from each [=ruby annotation container=] in its [=ruby segment=].

	If a [=ruby annotation container=] contains only
	a single, anonymous [=ruby annotation=],
	then that [=ruby annotation=] is paired with (i.e. [=spans=] across)
	all of the [=ruby bases=] in its [=ruby segment=].

	Otherwise, each [=ruby annotation=] is paired,
	in document order, with the corresponding [=ruby base=] in that segment.
	If there are not enough [=ruby annotations=] in a [=ruby annotation container=],
	the remaining [=ruby bases=] are paired with anonymous empty annotations
	inserted at the end of the [=ruby annotation container=].
	If there are not enough [=ruby bases=],
	any remaining [=ruby annotations=] pair with empty, anonymous bases
	inserted at the end of the [=ruby base container=].

	If an implementation supports ruby markup with explicit spanning
	(e.g. XHTML Complex Ruby Annotations),
	it must adjust the [=pairing=] rules to pair [=spanning annotations=]
	to their bases appropriately.

	[=Intra-level white space=] does not participate in standard annotation [=pairing=].
	However, if the immediately-adjacent [=ruby bases=] or [=ruby annotations=]
	are paired
	<ul>
		<li>
			with two [=ruby bases=] or [=ruby annotations|annotations=]
			that surround corresponding [=intra-level white space=] in another level,
			then the so-corresponding [=intra-level white space=] boxes are also paired.
		<li>
			with a single spanning [=ruby annotation=],
			then the [=intra-level white space=] is also paired to that [=ruby annotation=]
		<li>
			with two [=ruby bases=] or [=ruby annotations|annotations=]
			with no intervening [=intra-level white space=],
			then the [=intra-level white space=] box pairs with
			an anonymous empty [=intra-level white space=] box assumed to exist between them.
	</ul>


	<div class="example">
		The following diagram shows the pairing of
		regular [=base=] and [=annotation=] boxes
		as well as the pairing of [=intra-ruby white space=] (represented as <samp>ws</samp>):

		<pre class=highlight>
			<span class=column>|</span><span class=annot>[</span>  s p a n n i n g   a n n o t a t i o n <span class=annot>]</span><span class=column>|</span>
			<span class=column>|</span><span class=annot>[</span> a1 <span class=annot>]</span><span class=column>|</span><span class=annot>[</span>ws<span class=annot>]</span><span class=column>|</span><span class=annot>[</span> a2 <span class=annot>]</span><span class=column>|</span><span class=annot>[</span>  <span class=annot>]</span><span class=column>|</span><span class=annot>[</span> a3 <span class=annot>]</span><span class=column>|</span><span class=annot>[</span>ws<span class=annot>]</span><span class=column>|</span><span class=annot>[</span> a4 <span class=annot>]</span><span class=column>|</span>
			<span class=column>|</span><span class=base>[</span> b1 <span class=base>]</span><span class=column>|</span><span class=base>[</span>ws<span class=base>]</span><span class=column>|</span><span class=base>[</span> b2 <span class=base>]</span><span class=column>|</span><span class=base>[</span>ws<span class=base>]</span><span class=column>|</span><span class=base>[</span> b3 <span class=base>]</span><span class=column>|</span><span class=base>[</span>  <span class=base>]</span><span class=column>|</span><span class=base>[</span> b4 <span class=base>]</span><span class=column>|</span>
		</pre>

		Blue brackets (<samp class=base>[ ]</samp>) represent [=base boxes=],
		red brackets (<samp class=annot>[ ]</samp>) represent [=annotation boxes=],
		gray bars (<samp class=column>|</samp>) represent the limits of [=ruby columns=],
		<samp class=ws>[ws]</samp> represents [=intra-ruby white space=],
		and <samp>[]</samp> represents an empty anonymous base or annotation
		automatically generated to pair with [=intra-ruby white space=] in another level.
		[=Ruby containers=], [=base containers=], and [=annotation containers=] are omitted.

	</div>

<!--
	No longer needed now that the layout model is better defined,
	although we might want this (or something like this) if we want to handle
	complex cases for nesting with proper alignment across the nested parts

<h4 id="nested-pairing">
Complex Spanning with Nested Ruby</h4>

	When [=ruby containers=] are <dfn lt="nested ruby">nested</dfn>,
	[=pairing=] begins with the deepest [=ruby container=],
	then expands out.
	From the [=pairing=] perspective of the outer [=ruby container=],
	each [=ruby container=] nested within another [=ruby container=]
	counts as representing a single [=ruby base=]/[=annotation=] per level.
	The outer [=ruby container=]’s [=ruby annotations=] paired to the [=nested ruby=]
	are therefore paired with (and [=span=]) all of the nested [=ruby container=]’s [=ruby bases=].
	Each [=ruby annotation container=] in the nested [=ruby container=]
	occupies the same [=annotation level=] in the outer [=ruby container=]
	as it does in the inner one
	and participates in its layout as if it were directly contained in the outer [=ruby container=].

	This process is recursive.
	Thus, using nested [=ruby containers=] allows the representation
	of complex spanning relationships.

	Issue: It's not clear whether this falls out of layout handling of ruby containers inside ruby bases
	or needs to be handled specially.
	Waiting until layout is better-defined to find out...
-->

<h3 id="hiding" oldids="autohide">
Hiding Annotations: ''visibility: collapse'' and auto-hidden ruby</h3>

	A [=ruby annotation=] whose 'visibility' is ''visibility/collapse''
	is a <dfn lt="hidden annotation | hidden ruby annotation | hide" local-lt="hidden">hidden annotation</dfn>.
	Additionally,
	if a [=ruby annotation=] has the exact same text content as its base,
	it is automatically [=hidden=]
	(<dfn lt="auto-hidden | auto-hide">auto-hidden</dfn>)
	by the UA.

	[=Hiding=] a [=ruby annotation=] does not affect annotation [=pairing=].
	However the [=hidden annotation=] is not visible,
	and it has no impact on layout
	other than to separate adjacent sequences of [=ruby annotation boxes=] within its level,
	as if they belonged to separate segments
	and the [=hidden annotation=]’s base were not a [=ruby base=] but an intervening inline.

	<div class="example">
		Auto-hiding allows correct inlined display of annotations
		for Japanese words that are a mix of kanji and hiragana.
		For example, the word <span lang=ja>振り仮名</span> should be inlined as

		<p class="figure">振り仮名(ふりがな)

		and therefore marked up as
		<pre highlight=html>
			&lt;ruby>
				&lt;rb>振&lt;/rb>&lt;rb>り&lt;/rb>&lt;rb>仮&lt;/rb>&lt;rb>名&lt;/rb>
				&lt;rp>(&lt;/rp>&lt;rt>ふ&lt;/rt>&lt;rt>り&lt;/rt>&lt;rt>が&lt;/rt>&lt;rt>な&lt;/rt>&lt;rp>)&lt;/rp>
			&lt;/ruby></pre>

		However, when displayed as ruby, the “り” should be hidden
		<div class="figure">
			<img src="images/furigana-separate.png"
			     alt="Hiragana annotations for 振り仮名 appear, each pronunciation above its kanji base character.">
			<p class="caption">Hiragana ruby for <span lang=ja>振り仮名</span>. Notice there is no hiragana annotation above <span lang=ja>り</span>,  since it is already in hiragana.
		</div>
	</div>

	<div class="example">
		The Japanese word in this example is composed of three kanji characters,
		one of which is taught in first grade,
		while the other two are more advanced.
		(Characters colored to show base-pair correspondences.)

		<xmp highlight=html>
		<ruby><rb>昆<rb>虫<rb>記<rt>こん<rt class=easy>ちゅう<rt>き</ruby>
		</xmp>

		<figure>
			<img src="images/ruby-pairing-full.png" width=122
			     alt="昆虫記, with phonetic annotations on all three characters.
			     Because the middle annotation is wider than its base,
			     space has been introduced around the base character
			     to prevent its annotation from colliding with the adjacent annotations.">
			<figcaption>Fully annotated three-character word</figcaption>
		</figure>

		Although some readers might need pronunciation guidance
		on all three characters,
		for other audiences it is more appropriate
		to hide the annotation on the easier character.
		Applying ''visibility: collapse'' enables this hiding:

		<figure>
			<img src="images/ruby-pairing-collapse.png" width=105
			     alt="昆虫記, with phonetic annotations centered over
			          the first and last characters.">
			<figcaption>Middle annotation as ''visibility: collapse''</figcaption>
		</figure>

		The [=hiding=] behavior of ''visibility: collapse''
		differs from ''visibility: hidden''--
		which makes the annotation invisible,
		but does not remove its impact on layout:

		<figure>
			<img src="images/ruby-pairing-invisible.png" width=122
			     alt="昆虫記, with phonetic annotations on the first and last characters.
			     Over the second one, even though no annotation is showing,
			     space is reserved as if to hold it,
			     which pushes the base characters apart.">
			<figcaption>Middle annotation as ''visibility: hidden''</figcaption>
		</figure>

		It also differs from ''display: none''
		because ''visibility: collapse'' preserves pairing relationships,
		whereas ''display: none'' removes the box from the tree entirely,
		disturbing the pairing of any annotations after it:

		<figure>
			<img src="images/ruby-pairing-discard.png" width=107
			     alt="昆虫記, with mispaired phonetic annotations:
			     the annotation for the second character having been removed,
			     the annotation for the third character is displayed over the second one.">
			<figcaption>Middle annotation as ''display: none''</figcaption>
		</figure>
	</div>

	When the [=computed value=] of 'ruby-merge' on the [=annotation container=]
	is ''merge'',
	[=hiding=] is disabled.
	When that value is ''ruby-merge/auto'',
	the user agent may decide whether to disable [=hiding=] of its annotations,
	but it is recommended to enable [=hiding=]
	if the user agent’s layout algorithm
	produces the results similar to ''separate''.

	The content comparison for [=auto-hiding=]
	takes place prior to white space collapsing ('white-space') and text transformation ('text-transform')
	and ignores elements (considers only the <code>textContent</code> of the boxes).

	Note: Future levels of CSS Ruby may add controls for [=auto-hiding=],
	but in this level it is always forced.

<h3 id="white-space">
White Space Collapsing</h3>

	As discussed in [[#box-fixup]],
	white space within a ruby structure is <a href="#anon-gen-discard-space">discarded</a>:
	<ul>
		<li>at the beginning and end of a [=ruby container=], [=annotation container=], or [=base container=],
		<li>between a [=base container=] and its following [=annotation container=],
		<li>between [=annotation containers=].
	</ul>

	<div class="example">
		For example, the following markup will display without any spaces:
		<pre highlight=html>
			&lt;ruby>
				&lt;rb>東&lt;/rb>&lt;rb>京&lt;/rb>
				&lt;rt>とう&lt;/rt>&lt;rt>きょう&lt;/rt>
				&lt;rtc>&lt;rt>Tō&lt;/rt>&lt;rt>kyō&lt;/rt>&lt;/rtc>
			&lt;/ruby></pre>
	</div>

	Between [=ruby segments=], between [=ruby bases=], and between [=ruby annotations=], however,
	white space is not discarded,
	and is maintained for rendering
	as [=inter-base white space|inter-base=],
	[=inter-annotation white space|inter-annotation=],
	or [=inter-segment white space=].
	(See <a href="#anon-gen-interpret-space">Interpret intra-level white space</a>, above.)

	<div class="example">
		The rules preserving white space allow ruby to be used with space-separated scripts such as Latin.
		For example,
		<pre highlight=html>
			&lt;ruby>
				&lt;rb>W&lt;/rb>&lt;rb>W&lt;/rb>&lt;rb>W&lt;/rb>
				&lt;rt>World&lt;/rt> &lt;rt>Wide&lt;/rt> &lt;rt>Web&lt;/rt>
			&lt;/ruby></pre>

		They also ensure that annotated white space is preserved. For example,
		<pre highlight=html>
			&lt;ruby>
				&lt;rb>Aerith&lt;/rb>&lt;rb> &lt;/rb>&lt;rb>Gainsborough&lt;/rb>
				&lt;rt>エアリス&lt;/rt>&lt;rt>・&lt;/rt>&lt;rt>ゲインズブール&lt;/rt>
			&lt;/ruby></pre>
	</div>

	Where undiscarded white space is [=collapsible white space|collapsible=],
	it will collapse across adjacent boxes in each line box
	following the standard <a href="https://www.w3.org/TR/css3-text/#white-space-rules">white space processing rules</a> [[!CSS-TEXT-3]].
	Annotations in separate [=ruby segments=]
	or separated by [=hidden annotations=]
	are not considered adjacent;
	however all base-level content
	(including [=inter-character annotations=],
	which are treated as [=atomic inlines=])
	is.
	For [=collapsible white space=] between [=ruby segments=] ([=inter-segment white space=]),
	the contextual text for determining [[css-text-3#line-break-transform|segment break transformations]]
	is thus given by the [=ruby bases=] on either side,
	not necessarily the text on either side of the white space in source document order
	(which could include [=interlinear annotations=]).

	<div class="note">
		Note: The white space processing rules
		cause a white space sequence containing a [=segment break=] (such as a line feed)
		to <a href="https://www.w3.org/TR/css3-text/#line-break-transform">collapse to nothing</a> between Han and Kana characters.
		This means that Chinese and Japanese ruby can safely use white space for indentation of ruby markup.
		For example, the following markup will display without any spaces:
		<pre highlight=html>
			&lt;ruby>
				屋&lt;rt>おく&lt;/rt>内&lt;rt>ない&lt;/rt>
				禁&lt;rt>きん&lt;/rt>煙&lt;rt>えん&lt;/rt>
			&lt;/ruby></pre>

		However, white space that does not contain a [=segment break=] does not collapse completely away,
		so this markup will display with a space between the first and second ruby pairs:
		<pre highlight=html>
			&lt;ruby>
				屋&lt;rt>おく&lt;/rt>	内&lt;rt>ない&lt;/rt>
				禁&lt;rt>きん&lt;/rt>	煙&lt;rt>えん&lt;/rt>
			&lt;/ruby></pre>
	</div>

<h2 id="ruby-layout">
Ruby Layout</h2>

	When a ruby structure is laid out,
	its [=base level=] is initially laid out on the line
	exactly as if its [=ruby bases=] were a regular sequence of [=inline boxes=]
	and the [=ruby container=] a regular [=inline box=] wrapped around it.

	If a [=ruby container=] has any [=inter-character annotations=],
	they are laid out into the [=base level=] as detailed in [[#inter-character-layout]].
	Subsequently,
	the [=base container=] is sized and
	[=interlinear annotations=] are laid out
	as detailed in [[#interlinear-layout]].

	As in other CSS layout models,
	relative positioning, transforms, and other graphical effects
	apply after this layout of the boxes.

<h3 id="interlinear-layout">
Interlinear Ruby Layout</h3>

	[=Interlinear=] [=ruby annotations=] within a level
	are initially laid out as if they were [=inline boxes=]
	participating in the same [=inline formatting context=],
	effectively establishing a [=line box=]
	for that [=level=] of annotation in the [=ruby container=].
	[=Annotations=] and [=bases=] are aligned to each other
	by adjusting their spacing as described below.

<h4 id="interlinear-inline">
Inline-axis Interlinear Layout</h4>

	In the inline axis, [=interlinear=] [=ruby annotations=] are aligned
	with respect to their [=ruby base boxes=]
	in accordance with their [=annotation container=]’s 'ruby-merge' value.

	When 'ruby-merge' is ''ruby-merge/separate'',
	each [=ruby column=] is sized
	to the widest content ([=ruby base=] or [=ruby annotation=]) in that [=column=].
	In the case of [=spanning annotations=]
	(whether actually spanning or pretending to span per ''ruby-merge: merge''),
	if the content of a [=spanning annotation=] would be wider
	than the [=columns=] that it spans,
	then the difference is distributed equally among the spanned [=columns=].
	If a [=ruby segment=] contains multiple [=spanning annotations=],
	this distribution of additional space
	is performed starting with the [=spanning annotations=]
	that span the least number of bases,
	and then in increasing number of bases spanned.
	Each [=ruby base=] and [=ruby annotation=]
	is then sized to exactly span its column(s).

	Note: If there are multiple annotations in different levels spanning the same number of bases
	that overlap but do not coincide,
	the distribution of space is undefined.
	Note this is not possible with HTML markup,
	but can happen in markup languages with explicit spanning such as in [[RUBY]].

	If any [=ruby annotation=] in an [=annotation container=] with ''ruby-merge: auto''
	is wider than its [=ruby base|base=],
	then [=ruby annotations=] in that [=annotation container=]
	may extend outside of their [=column=](s).
	When they do, their influence on
	the measure of the [=columns=] they intersect
	is up to the user agent,
	provided that the [=ruby segment=] is made wide enough to fit all its content.

	[=Inter-character=] annotations are interleaved between columns:
	they factor into measurement of annotations that span both adjacent columns,
	but are not included in either column
	and are never affected by the sizing or positioning
	of [=interlinear annotations=].

	Within each [=base=] and [=annotation=] box,
	how the extra space is distributed
	when its content is narrower than the measure of the box
	is specified by its 'ruby-align' property.

	<div class=example>
		The following diagrams illustrate these rules,
		covering typical situations
		as well as a few more complex ones.
		In each case,
		[=base boxes=] and [=annotation boxes=] are assumed to have ''ruby-align: center'',
		while <!--[=base containers=] and --> [=annotation containers=] are assumed to have ''ruby-align: space-between''.

		Blue brackets (<samp class=base>[ ]</samp>) represent [=base boxes=],
		red brackets (<samp class=annot>[ ]</samp>) represent [=annotation boxes=],
		and gray bars (<samp class=column>|</samp>) represent the limits of [=ruby columns=].
		[=Ruby containers=], [=base containers=], and [=annotation containers=] are omitted.

		<dl>
			<dt id=ex-separate>Separate / non-spanning:
			<dd>
				<pre class=highlight>
				<span class=column>|</span><span class=annot>[</span>  a1  <span class=annot>]</span><span class=column>|</span><span class=annot>[</span>  a2  <span class=annot>]</span><span class=column>|</span><span class=annot>[</span>annotation-3<span class=annot>]</span><span class=column>|</span>
				<span class=column>|</span><span class=base>[</span>base 1<span class=base>]</span><span class=column>|</span><span class=base>[</span>base 2<span class=base>]</span><span class=column>|</span><span class=base>[</span>   base 3   <span class=base>]</span><span class=column>|</span>
				</pre>

				Boxes within each [=column=] are sized to match the widest box of that [=column=].
				The value of 'ruby-align' on each [=base box=] and [=annotation box=] is used
				to distribute the extra space in each box.

			<dt id=ex-short-span>Spanning (short):
			<dd>
				<pre class=highlight>
				<span class=column>|</span><span class=annot>[</span>  a1  <span class=annot>]</span><span class=column>|</span><span class=annot>[</span>   short span  <span class=annot>]</span><span class=column>|</span>
				<span class=column>|</span><span class=base>[</span>base 1<span class=base>]</span><span class=column>|</span><span class=base>[</span>base 2<span class=base>]</span><span class=column>|</span><span class=base>[</span>base 3<span class=base>]</span><span class=column>|</span>
				</pre>

				When a [=spanning annotation=] is shorter than the spanned [=bases=],
				there is no extra space to distribute to these [=bases=].
				Extra space within the [=spanning annotation=]
				is distributed according to 'ruby-align' on that [=annotation box=],
				as for non spanning ones.

			<dt id=ex-long-span>Spanning (long):
			<dd>
				<pre class=highlight>
				<span class=column>|</span><span class=annot>[</span>  a1  <span class=annot>]</span><span class=column>|</span><span class=annot>[</span>spanning annotation<span class=annot>]</span><span class=column>|</span>
				<span class=column>|</span><span class=base>[</span>base 1<span class=base>]</span><span class=column>|</span><span class=base>[</span> base 2 <span class=base>]</span><span class=column>|</span><span class=base>[</span> base 3 <span class=base>]</span><span class=column>|</span>
				</pre>

				When the [=spanning annotation=] is longer than the spanned [=base boxes=],
				the extra space is distributed equally between them.

			<dt id=ex-short-merge>Merged (short):
			<dd>
				<pre class=highlight>
				<span class=column>|</span><span class=annot>[</span>merged        annotation<span class=annot>]</span><span class=column>|</span>
				<span class=column>|</span><span class=base>[</span>base 1<span class=base>]</span><span class=column>|</span><span class=base>[</span>base 2<span class=base>]</span><span class=column>|</span><span class=base>[</span>base 3<span class=base>]</span><span class=column>|</span>
				</pre>

				A [=merged annotation=] behaves similarly to a [=spanning=] one,
				except that distribution of any extra space in it
				is determined by the value of 'ruby-align' on the [=annotation container=],
				not on any of its [=annotation boxes=].

<!--
			<dt id=ex-long-merge>Merged (long):
			<dd>
				<pre>
				|[This is a long merged annotation]| <- no extra space, nothing to align
				|[ Base 1  ]|[ Base 2 ]|[ Base 3  ]| <- uses ruby-align on each base like for a spanner?
				or maybe (see https://github.com/w3c/csswg-drafts/issues/6004)
				|[Base 1       Base 2       Base 3]| <- treats the bases as merged as well?
				</pre>
-->
			<dt id=ex-multi-level-span>Several levels, with spanning annotation:
			<dd>
				<pre class=highlight>
				<span class=column>|</span><span class=annot>[</span>   a1   <span class=annot>]</span><span class=column>|</span><span class=annot>[</span> annotation-2 <span class=annot>]</span><span class=column>|</span><span class=annot>[</span>   a3   <span class=annot>]</span><span class=column>|</span>
				<span class=column>|</span><span class=annot>[</span>long annotation spanning all content<span class=annot>]</span><span class=column>|</span>
				<span class=column>|</span><span class=base>[</span> base 1 <span class=base>]</span><span class=column>|</span><span class=base>[</span>    base 2    <span class=base>]</span><span class=column>|</span><span class=base>[</span> base 3 <span class=base>]</span><span class=column>|</span>
				</pre>
				<pre class=highlight>
				<span class=column>|</span><span class=annot>[</span>  xx  <span class=annot>]</span><span class=column>|</span><span class=annot>[</span>annotation spanning bases<span class=annot>]</span><span class=column>|</span>
				<span class=column>|</span><span class=annot>[</span>  a1  <span class=annot>]</span><span class=column>|</span><span class=annot>[</span> annotation-2 <span class=annot>]</span><span class=column>|</span><span class=annot>[</span>   a3   <span class=annot>]</span><span class=column>|</span>
				<span class=column>|</span><span class=base>[</span>base 1<span class=base>]</span><span class=column>|</span><span class=base>[</span>    base 2    <span class=base>]</span><span class=column>|</span><span class=base>[</span> base 3 <span class=base>]</span><span class=column>|</span>
				</pre>

				In these two examples with multiple [=levels=],
				each [=column=] is sized to its longest content,
				and [=spanning annotations=] that are still longer
				than the sum of the [=columns=] that they span
				grow them further,
				adding to each equally.

			<dt id=ex-multi-level-multi-span>Several levels, with multiple spanning annotations:
			<dd>
				<pre class=highlight>
				<span class=column>|</span><span class=annot>[</span><span class=flagbg2> </span>  xx  <span class=flagbg2> </span><span class=annot>]</span><span class=column>|</span><span class=annot>[</span><span class=flagbg2>  </span><span class=flagtxt1>annotation spanning bases</span><span class=flagbg2>  </span><span class=annot>]</span><span class=column>|</span>
				<span class=column>|</span><span class=annot>[</span><span class=flagbg2> </span>  a1  <span class=flagbg2> </span><span class=annot>]</span><span class=column>|</span><span class=annot>[</span><span class=flagbg2> </span><span class=flagbg1> </span>annotation-2<span class=flagbg1> </span><span class=flagbg2> </span><span class=annot>]</span><span class=column>|</span><span class=annot>[</span><span class=flagbg2> </span><span class=flagbg1> </span>  a3  <span class=flagbg1> </span><span class=flagbg2> </span><span class=annot>]</span><span class=column>|</span>
				<span class=column>|</span><span class=annot>[</span><span class=flagtxt2>lengthy annotation spanning base content</span><span class=annot>]</span><span class=column>|</span>
				<span class=column>|</span><span class=base>[</span><span class=flagbg2> </span>base 1<span class=flagbg2> </span><span class=base>]</span><span class=column>|</span><span class=base>[</span><span class=flagbg2> </span><span class=flagbg1> </span>   base 2   <span class=flagbg1> </span><span class=flagbg2> </span><span class=base>]</span><span class=column>|</span><span class=base>[</span><span class=flagbg2> </span><span class=flagbg1> </span>base 3<span class=flagbg1> </span><span class=flagbg2> </span><span class=base>]</span><span class=column>|</span>
				</pre>

				When there are multiple [=spanning annotations=],
				those that span fewest [=bases=] are processed first.
				In this case, the green one,
				which spans two bases,
				is processed before the orange one,
				which spans three.
				Changing this order would change the distribution of space.

				To help identify which [=spanning annotation=] is responsible
				for which extra spacing,
				in this diagram
				the color of the text in each [=spanning annotation=] is matched
				with the background color of spacing it adds to other boxes.
		</dl>
	</div>

<h4 id="interlinear-block">
Block-axis Interlinear Layout</h4>

	ISSUE: Define the extent to which 'vertical-align' affects these ruby boxes.
	See <a href="https://github.com/w3c/csswg-drafts/issues/4987">Issue 4987</a>.

	Each [=base container=] is then sized and positioned
	to contain exactly all of its [=ruby bases=]’ margin boxes--
	and all their associated [=inter-character=] [=ruby annotation=] margin boxes, if any--
	as well as the [=base containers|base=] and [=annotation containers=]
	of any descendant [=ruby containers=]
	also participating in this [=inline formatting context=].
	(If a [=base container=] has no [=in-flow=] content,
	it is sized and positioned
	as if it contained a single empty [=ruby base=].)

	Each [=interlinear=] [=annotation container=] is sized and positioned
	to contain exactly all of its [=ruby annotations=]’ margin boxes
	as well as the [=base containers|base=] and [=annotation containers=]
	of any descendant [=ruby containers=]
	also participating in this [=annotation level=]’s [=inline formatting context=].
	(If an [=annotation container=] has no [=in-flow=] content,
	it is sized and positioned
	as if it contained a single empty [=ruby annotation=].)
	These [=annotation containers=] are then stacked outward
	over or under (depending on 'ruby-position') their corresponding [=base container=],
	without any intervening space,
	thus determining the block-axis positioning of the [=ruby annotations=]
	with respect to their [=ruby bases=].

	Issue: Should block-axis margins collapse?
	This makes layout more robust,
	but is inconsistent with how inlines behave along the inline-axis.

<h3 id="inter-character-layout">
Inter-character Ruby Layout</h3>

	[=Inter-character annotations=] have special layout.
	[=Inter-character=] [=ruby annotation boxes=]
	are spliced into and measured as part of the layout of the [=base level=].
	Each [=ruby annotation=] is inserted to the right of the [=ruby base=] it is paired with;
	a [=spanning=] [=inter-character annotation=] is placed after
	the rightmost of all the bases that it spans.
	[=Inter-character=] [=ruby annotations=] are laid out
	exactly like [=inline blocks=],
	except as described below.

	Note: As per the definition of ''inter-character'',
	[=inter-character annotations=] always have a ''vertical-rl'' 'writing-mode',
	and only exist in [=horizontal writing mode|horizontal=] [=ruby containers=].

	Each [=ruby annotation=] is placed immediately to the right of the relevant [=ruby base=],
	before any [=inter-base white space=] (or [=inter-segment white space=]).
	If multiple [=inter-character=] [=ruby annotation boxes=] are placed against the same [=ruby base=],
	their [=margin boxes=] are stacked rightwards without intervening space,
	in increasing [=level=] order.

	If the [=automatic size|automatic height=] of the [=ruby annotation box=]’s [=content area=]
	would be shorter than the height of the [=content box=]
	of the [=ruby base=] after which it is placed,
	its [=content box=] height is increased to match that height exactly.

	The alignment of the [=ruby annotation box=]
	depends on the 'ruby-align' property on the [=ruby annotation=]:

	<ul>
		<li>
			If 'ruby-align' is ''ruby-align/start'',
			the top edge of the [=ruby annotation=]'s [=content box=] is aligned
			with the top edge of the [=ruby base=]'s [=content box=].

			<li>
				Otherwise,
				the center of the [=ruby annotation=]'s [=content box=] is vertically aligned
				with the center of the [=ruby base=]'s [=content box=].
	</ul>

	The [=ruby annotation container box=] of an [=inter-character=] annotation
	is sized and placed so that its content box coincides exactly with that of the [=ruby base container box=].

	Note: The size and position of [=inter-character=] [=ruby annotation container boxes=]
	has no effect on layout.
	The above definition is merely so that programmatically inquiring about them
	produces deterministic results.

	For the purpose of [[#ruby-align-property|alignment]]
	and column sizing (as discussed in [[#ruby-layout]]),
	[=inter-character=] [=ruby annotations=] are not considered
	to be part of the same [=column=] as the base to with they are attached;
	rather, they effectively form a [=column=] of their own.


<h3 id="box-style">
Styling Ruby Boxes</h3>

	[=Ruby bases=] and [=ruby containers=] are treated as [=inline boxes=],
	and all properties that apply to [=inline boxes=],
	unless otherwise specified,
	also apply to them in the same way.
	However, the <a spec=css-inline-3>line-relative shift values</a> of 'vertical-align'
	(''vertical-align/top'', ''vertical-align/bottom'')
	must be ignored (treated as zero).

	All properties that apply to [=inline boxes=],
	unless otherwise specified,
	also apply to [=ruby annotations=] in the same way,
	except 'line-height', which does not apply.
	Also, the <a spec=css-inline-3>line-relative shift values</a> of 'vertical-align'
	(''vertical-align/top'', ''vertical-align/bottom'')
	must be ignored (treated as zero).

	Neither the [=margin=], [=padding=], [=border=] properties
	nor the any properties that do not apply to [=inline boxes=]
	apply to [=base containers=] or [=annotation containers=].
	Additionally, 'line-height' does not apply to [=annotation containers=].

	The UA is not required to support
	any of the background properties or outline properties,
	or any other property that illustrates the bounds of the box
	on [=ruby base container boxes=] or [=ruby annotation container boxes=].
	The UA may implement these boxes simply as abstractions for inheritance
	and control over the layout of their contents.

<h3 id="line-breaks">
Breaking Across Lines</h3>

	When there is not enough space for an entire [=ruby container=] to fit on the line,
	the ruby may be broken wherever all levels simultaneously allow a break.
	(See [[CSS-TEXT-3#line-breaking]] for details on line breaking.)
	Ruby most often breaks between base-annotation sets,
	but if the line-breaking rules allow it, can also break within a [=ruby base=]
	(and, in parallel, its associated [=ruby annotation boxes=]).

	Whenever ruby breaks across lines, [=ruby annotations=] must stay
	with their respective [=ruby bases=].
	The line <em>must not</em> break between a [=ruby base=] and its [=annotations=],
	even in the case of [=inter-character annotations=].

	<div class="figure">
		<img src="images/r-break-b.gif"
		     alt='Diagram showing the line breaking opportunity in a "Bopomofo" ruby'>
		<p class="caption">''inter-character'' ruby line breaking opportunity
	</div>

	After line-breaking,
	each fragment is [[#ruby-layout|laid out]] independently,
	and [[#ruby-align-property|ruby alignment]] takes place within each fragment.

<h4 id="break-between">
Breaking Between Bases</h4>

	In typical cases, [=ruby base boxes=] and [=ruby annotation boxes=]
	are styled to forbid internal line wrapping and do not contain forced breaks.
	(See <a href="#default-stylesheet">Appendix A</a>.)
	In such cases the [=ruby container=] can only break between adjacent [=ruby bases=],
	and only if no [=ruby annotations=] span those [=ruby bases=].

	<div class="figure">
		<img src="images/r-break-a.gif"
		     alt="Diagram showing the line breaking opportunity in a complex ruby">
		<p class="caption">Ruby line breaking opportunity
	</div>

	Whether ruby can break between two adjacent [=ruby bases=]
	is controlled by normal line-breaking rules for the base text,
	exactly as if the [=ruby bases=] were adjacent inline boxes.
	(The annotations are ignored when determining soft wrap opportunities for the [=base level=].)

	<div class="example">
		For example, if two adjacent ruby bases are “蝴” and “蝶”,
		the line may break between them,
		because lines are normally allowed to break between two Han characters.
		However, if 'word-break' is ''keep-all'', that line break is forbidden.
		<pre highlight=html>&lt;ruby>蝴&lt;rt>hú&lt;/rt>蝶&lt;rt>dié&lt;/rt></pre>
	</div>

	Inter-base white space is significant for evaluating line break opportunities between [=ruby bases=].
	As with white space between inlines,
	it collapses when the line breaks there,
	following the rules detailed in [[CSS-TEXT-3#white-space-rules]].
	Similarly, annotation white space is also trimmed at a line break.

	<div class="example">
		For example, given the following markup:
		<pre highlight=html>&lt;ruby>&lt;rb>one&lt;/rb> &lt;rb>two&lt;/rb> &lt;rt>1&lt;/rt> &lt;rt>2&lt;/rt>&lt;/ruby></pre>

		Due to the space, the line may break between “one” and “two“.
		If the line breaks there, that space&mdash;and the space between “1” and “2”&mdash;disappears,
		in accordance with standard CSS white space processing rules.
	</div>

<h4 id="break-within">
Breaking Within Bases</h4>

	For longer base texts, it is sometimes appropriate to allow breaking within a base-annotation pair.
	For example, if an English sentence is annotated with its Japanese translation,
	allowing the text to wrap allows for reasonable line breaking behavior in the paragraph.

	Issue: Insert scanned example so people don't think this is just the ramblings of an insane spec-writer.

	Line-breaking within a [=ruby base=] is only allowed if the 'white-space' property
	of the [=ruby base=] and all its parallel [=annotations=] allow it,
	and there exists a [=soft wrap opportunity=] <em>within</em> (i.e. not at the start or end)
	the content of each base/annotation box.
	Since there is no structural correspondence between fragments of content
	within [=ruby bases=] and [=annotations=],
	the UA may break at any set of opportunities;
	but it is recommended that the UA attempt to proportionally balance
	the amount of content inside each fragment.

	There are no line breaking opportunities within [=inter-character annotations=].

<h3 id="bidi">
Bidi Reordering</h3>

	The Unicode bidirectional algorithm reorders logically-stored text for visual presentation
	when characters from scripts of opposing directionalities are mixed
	within a single paragraph.

	To preserve the correspondence of [=ruby annotations=]
	to their respective [=ruby bases=],
	a few restrictions must be imposed:
	<ul>
		<li>The contents of a [=ruby base=] or [=ruby annotation=] must remain contiguous.
		<li>[=Ruby annotations=] must be reordered together with their [=ruby bases=].
		<li>All [=ruby bases=] spanned by a single [=ruby annotation=] must remain contiguous.
	</ul>

	To this end,
	<ul>
		<li>
			Bidi isolation is forced on all [=internal ruby boxes=] and the [=ruby container=]:
			the ''unicode-bidi/normal'' and ''embed'' values of 'unicode-bidi' compute to ''isolate'',
			and ''bidi-override'' computes to ''isolate-override''.

			Note: This means that implicit bidi reordering does not work across ruby bases,
			so authors will need to ensure that the [=ruby container=]’s declared directionality
			does indeed match its contents.
		<li>
			During layout, [=ruby segments=] are ordered within the [=ruby container=]
			by the 'direction' property of their [=ruby container=].
		<li>
			Within a segment, [=ruby bases=] and [=ruby annotations=]
			that are not [=merged=]
			are ordered within their respective containers
			by the 'direction' property of the segment’s [=ruby base container=].
			[=Merged annotations=] are ordered
			by the 'direction' property of their [=annotation container=],
			exactly as if they were a sequence of inline boxes within their [=annotation container=].

			Note: This means the 'direction' property on [=ruby annotation containers=]
			is ignored for the purpose of layout of non-[=merged=] annotations.
			However, it can still inherit into the container's children
			and thereby affect the [=inline base direction=]
			of any [=ruby annotations=] it contains.
	</ul>

	As with other inline-level content,
	the bidi reordering of [=internal ruby boxes=] happens after line-breaking
	so that content is divided across lines according to its logical order.

	Note: It could be useful to adjust these rules slightly
	so that when 'ruby-merge' is ''merge'' on a particular [=annotation container=],
	bidi isolation is not forced onto the individual annotations,
	enabling them to be processed together.
	However, this would add complexity to implementations,
	which does not seem justified in the absence of demand to handle this situation.
	Anyone with a need for this to be handled
	is encouraged to contact the CSS Working Group.

	See [[CSS3-WRITING-MODES]] for a more in-depth discussion of bidirectional text in CSS.

	<!-- Some alternate proposals exist in the 2013 draft's comments section. -->

<h3 id="line-height">
Line Spacing</h3>

	The 'line-height' property controls spacing between lines in CSS.
	When inline content on line is shorter than the 'line-height',
	half-leading is added on either side of the content,
	as specified in [[CSS-INLINE-3#line-height]].

	In order to ensure consistent spacing of lines,
	documents with ruby typically ensure that the 'line-height' is large enough
	to accommodate ruby between lines of text.
	Therefore, ordinarily, [=ruby annotation containers=] and [=ruby annotation boxes=]
	do not contribute to the measured height of a line's inline contents;
	any alignment (see 'vertical-align') and line-height calculations
	are performed using only the [=ruby base container=],
	exactly as if it were a normal inline.

	However, if the 'line-height' specified on the [=ruby container=]
	is less than the distance between
	the top of the top [=ruby annotation container=]
	and the bottom of the bottom [=ruby annotation container=],
	then additional leading is added
	on the appropriate side(s) of the [=ruby base container=]
	such that if a block consisted of three lines
	each containing ruby identical to this,
	none of the [=ruby containers=] would overlap.

	Note: This does not ensure that the [=ruby annotations=] remain within the line box.
	It merely ensures that <em>if all lines had equal spacing</em>
	and equivalent amounts and positioning of [=ruby annotations=],
	there would be enough room to avoid overlap.

	Authors should ensure appropriate 'line-height' and 'padding' to accommodate ruby,
	and be particularly careful at the beginning or end of a block
	and when a line contains inline-level content
	(such as images, inline blocks, or elements shifted with 'vertical-align')
	taller than the paragraph's default font size.

	<div class="figure">
		<img src="images/rlh-a.gif"
		     alt="The content of each line sits in the middle of its line height;
		          the additional space on each side is called half-leading.
		          Ruby fits between lines if it is smaller than twice the half-leading,
		          but this means that it occupies space belonging to the half-leading of the previous line.">
		<p class="caption">Ruby annotations will often overflow the line;
		authors should ensure content over/under a ruby-annotated line
		is adequately spaced to leave room for the ruby.
	</div>

	Note: More control over how ruby affects alignment and line layout
	will be part of the CSS Line Layout Module Level 3.
	Note, it is currently in the exploratory stages of development;
	descriptions of new features should not yet be relied upon.

<h2 id="ruby-props">
Ruby Formatting Properties</h2>

	The following properties are introduced to control ruby
	<a href="#rubypos">positioning</a>,
	<a href="#collapsed-ruby">text distribution</a>,
	and <a href="#rubyalign">alignment</a>.

<h3 id="rubypos">
Ruby Positioning: the 'ruby-position' property</h3>

	<pre class="propdef">
	Name: ruby-position
	Value: [ alternate || [ over | under ] ] | inter-character
	Initial: alternate
	Applies to: ruby annotation containers
	Inherited: yes
	Computed value: specified keyword
	Animation type: discrete
	</pre>

	This property controls position of the [=ruby annotation=] with respect to its base.
	Values have the following meanings:

	<dl dfn-for=ruby-position dfn-type=value>
		<dt><dfn>alternate</dfn>
		<dd>
			Different [=levels=] of annotations alternate between ''over'' and ''under''.

			If the [=annotation container=] is the first [=level=] of annotation in its [=ruby segment=],
			or if all prior [=levels=] are [=inter-character=],
			then ''alternate'', either on its own or in combination with ''over'',
			behaves the same as ''over'',
			while ''alternate'' in combination with ''under''
			behaves the same as ''under''.

			Otherwise,
			if the previous level of [=interlinear=] annotation is ''over'',
			''alternate''  behaves like ''under'',
			and vice versa.
			(In this case, whether ''alternate'' is specified alone
			or in combination with ''over'' or ''under''
			makes no difference.)

		<dt><dfn>over</dfn>
		<dd>
			The ruby annotation appears [=line-over=] the base.

			<div class="figure">
				<img src="images/shinkansen-top.gif"
				     alt="Diagram of ruby glyph layout in horizontal mode with ruby annotation appearing above the base">
				<p class="caption">Ruby over Japanese base text in horizontal layout
			</div>
			<div class="figure">
				<img src="images/shinkansen-right.gif" width="33"
				     alt="Diagram of ruby glyph layout in vertical mode with ruby annotation appearing vertically on the right of the base">
				<p class="caption">Ruby to the right of Japanese base text in vertical layout
			</div>
		</dd>

		<dt><dfn>under</dfn>
		<dd>
			The ruby annotation appears [=line-under=] the base.
			This is a relatively rare setting used in ideographic East Asian writing systems,
			most easily found in educational text.

			<div class="figure">
				<img src="images/shinkansen-bottom.gif"
				     alt="Diagram of ruby glyph layout in horizontal mode with ruby annotation appearing below the base">
				<p class="caption">Ruby under Japanese base text in horizontal layout
			</div>
			<div class="figure">
				<img src="images/shinkansen-left.gif"
				     alt="Diagram of ruby glyph layout in vertical mode with ruby annotation appearing vertically on the left of the base">
				<p class="caption">Ruby to the left of Japanese base text in vertical layout
			</div>
		</dd>

		<dt><dfn>inter-character</dfn></dt>
		<dd>
			If the [=writing mode=] of the enclosing [=ruby container=] is [=vertical writing mode|vertical=],
			this value has the same effect as ''over''.

			Otherwise, the ruby annotation becomes an <dfn dfn local-lt=inter-character>inter-character annotation</dfn>.
			The annotation appears on the right of the base in horizontal text.
			This forces the computed value of 'writing-mode' of the [=ruby annotation=] children of this [=ruby annotation container=] to be ''vertical-rl''.

			Note: The computed value of 'writing-mode' on the [=ruby annotation container=] itself is not affected.
			This is to avoid circular dependencies between computed values
			on the 'writing-mode', 'display', and 'ruby-position' properties on the same element.

			This value is provided for the special case of traditional Chinese
			as used especially in Taiwan:
			ruby (made of <a href="#g-bopomofo">bopomofo</a> glyphs) in that context
			appears vertically along the right side of the base glyph,
			even when the layout of the base characters is horizontal:

				<div class="figure">
					<img src="images/bopomofo.gif"
					     alt="Example of Taiwanese-style ruby">
					<p class="caption">“Bopomofo” ruby in traditional Chinese
					(ruby annotation shown in blue for clarity) in horizontal layout
				</div>

			<div class=note>
				Note: As inheritance works on the element tree without accounting for anonymous boxes created for ruby layout,
				when using [=inter-character annotations=]
				authors need to be careful to avoid markup patterns involving
				an element-based [=ruby annotation container=],
				an anonymous [=ruby annotation=],
				and further descendant elements,
				as those descendants would inherit their writing mode from the [=ruby annotation container=],
				and not from the [=ruby annotation=] whose 'writing-mode' has been changed to ''vertical-rl''.

				<div class=example>
					<pre highlight=css>ruby { ruby-position: inter-character; }</pre>
					<xmp highlight=html><ruby>base<rtc><em>problematic</em> annotation</ruby></xmp>

					In the above markup, an anonymous [=ruby annotation=] box is created as a child of the <code>&lt;rtc></code> element
					to wrap the whole “problematic annotation”.
					Since it is a child of an [=annotation container=] whose 'ruby-position' is ''inter-character'',
					its 'writing-mode' will be ''vertical-rl'', which is expected.
					However, the <code>&lt;em></code> element inherits its 'writing-mode' directly from the <code>&lt;rtc></code> element,
					which has not been forced to ''vertical-rl''.

					In this example, the explicit [=ruby annotation container=] element was not necessary,
					so using a [=ruby annotation=] element instead would avoid the problem:

					<xmp highlight=html><ruby>base<rt><em>problematic</em> annotation</ruby></xmp>

					If an explicit [=ruby annotation container=] element is needed,
					then using a [=ruby annotation=] element as well would also address the problem:
					<xmp highlight=html><ruby>base<rtc><rt><em>problematic</em> annotation</ruby></xmp>
				</div>
			</div>

		</dd>
	</dl>

	[=Annotation containers=] that are not [=inter-character annotations=]
	are called <dfn local-lt="interlinear">interlinear annotations</dfn>.

	If multiple [=ruby annotation containers=] have the same 'ruby-position',
	they stack outwards from the base text.


<h3 id="collapsed-ruby">
Sharing Annotation Space: the 'ruby-merge' property</h3>

	<pre class="propdef">
	Name: ruby-merge
	Value: separate | merge | auto
	Initial: separate
	Applies to: [=interlinear=] ruby annotation containers
	Inherited: yes
	Computed value: specified keyword
	Animation type: by computed value type
	</pre>

	This property controls how ruby annotation boxes should be rendered
	when there are more than one in a ruby container box:
	whether each pair should be kept separate,
	the annotations should be <dfn lt="merged annotation | merged">merged</dfn> and rendered as a group,
	or the separation should be determined based on the space available.

	Note: [=Inter-character annotations=] are always separate, and this property does not apply.

	Possible values:
	<dl dfn-for=ruby-merge dfn-type=value>
		<dt><dfn>separate</dfn>
		<dd>
			Each ruby annotation box is rendered within
			the same [=column=](s) as its corresponding base box(es),
			i.e. without overlapping adjacent bases on either side.
			This style is called “mono ruby” in [[JLREQ]].

			<figure>
				<img src="images/ruby-mono.png"
				     alt="Extra space is added to base or annotations
				          when one of the pair is longer than the other
				          in order to keep each annotation exclusive to its own base.
				          For example, in the annotation for “上手”,
				          extra space is added around the first character
				          to accommodate its longer annotation “じょう”
				          while the shorter annotation “ず” for the second character
				          is simply positioned and aligned with respect to its base characters.">
				<figcaption>''ruby-merge: separate'' with center alignment</figcaption>
			</figure>

			<div class="example">
				For example, the following two lines render the same:
				<pre highlight=html>
					&lt;p>&lt;ruby&gt;無&lt;rt&gt;む&lt;/ruby&gt;&lt;ruby&gt;常&lt;rt&gt;じょう&lt;/ruby&gt;
					&lt;p>&lt;ruby style="ruby-merge:separate"&gt;&lt;rb&gt;無&lt;rb&gt;常&lt;rt&gt;む&lt;rt&gt;じょう&lt;/ruby&gt;</pre>
			</div>
		</dd>

		<dt><dfn>merge</dfn>
		<dd>
			All [=ruby annotation boxes=] within the same [=ruby segment=] on the same line are concatenated
			as [=inline boxes=] within their [=annotation container=],
			and laid out in a single anonymous [=ruby annotation box=]
			spanning all their associated [=ruby base boxes=].
			When laid out on a single line,
			this style renders similar to “group ruby” in [[JLREQ]].
			However, when it breaks across lines,
			[=ruby annotations=] are kept together with their respective [=ruby bases=].

			<figure>
				<img src="images/ruby-merge.png"
				     alt="The combined annotation is centered with respect to the combined base,
				          even if this would place an annotation’s content over a different base.
				          In the case of “上手”, the “う” from the first base’s annotation
				          and the “ず” from the second base’s annotation end up
				          sharing space over the second base.">
				<figcaption>''ruby-merge: merge'' with center alignment</figcaption>
			</figure>

			<div class="example">
				The following two lines render the same
				if both characters fit on one line:
				<pre highlight=html>
					&lt;p>&lt;ruby&gt;無常&lt;rt&gt;むじょう&lt;/ruby&gt;
					&lt;p>&lt;ruby style="ruby-merge:merge"&gt;&lt;rb&gt;無&lt;rb&gt;常&lt;rt&gt;む&lt;rt&gt;じょう&lt;/ruby&gt;</pre>
				However, the second one renders the same as ''ruby-position: separate''
				when the two bases are split across lines.
			</div>
		</dd>

		<dt><dfn>auto</dfn></dt>
		<dd>
			The user agent may use any algorithm to determine how each ruby annotation box
			is rendered to its corresponding base box,
			with the intention that if all annotations fit over their respective bases,
			the result is identical to ''separate'',
			but if some annotations are wider than their bases
			the space is shared in some way
			to avoid imposing space between bases.

			<figure>
				<img src="images/ruby-jukugo.png"
				     alt="If there is enough space, annotations are aligned to their bases;
				          but if there is not, then annotations can share space with adjacent annotations.
				          Thus the annotations for “上手” share space over the second base as in the 'merge' case,
				          but the annotations for “下手” which are one character each
				          end up rendering as for 'separate'.">
				<figcaption>''ruby-merge: auto'' with center alignment</figcaption>
			</figure>

			<div class="note">
				Note: This behavior is intended for compound words,
				see <a href="https://www.w3.org/International/questions/qa-ruby#jukugo">“Jukugo Ruby” in “What is ruby?”</a>. [[QA-RUBY]]

				There are various conventions for rendering this type of ruby,
				see <a href="https://www.w3.org/TR/simple-ruby/#placement-of-jukugo-ruby">Placement of Jukugo-ruby</a> in [[SIMPLE-RUBY]],
				<a href="https://www.w3.org/TR/jlreq/#positioning_of_jukugoruby_with_respect_to_base_characters">Positioning of Jukugo-ruby</a> in [[JLREQ]],
				and <cite>4.12.3(c) 熟語ルビの処理</cite> in [[JISX4051]]
				for examples of varying complexity.

				The simplest of these is
				to render as ''separate'' if all ruby annotation boxes fit
				within the advances of their corresponding base boxes,
				and render as ''merge'' otherwise.
			</div>
		</dd>
	</dl>

	Note: Text does not shape or form ligatures
	across [=ruby annotations=] or [=ruby base|bases=],
	even merged ones,
	due to [=bidi isolation=].
	See [[#bidi]] and [[css-text-3#boundary-shaping]].

<h3 id="ruby-align-property"><span id="rubyalign"></span>
Ruby Text Distribution: the 'ruby-align' property</h3>

	<pre class="propdef">
	Name: ruby-align
	Value: start | center | space-between | space-around
	Initial: space-around
	Applies to: ruby bases, ruby annotations, ruby base containers, ruby annotation containers
	Inherited: yes
	Computed value: specified keyword
	Animation type: by computed value type
	</pre>

	This property specifies how text is distributed within the various ruby boxes
	when their contents do not exactly fill their respective boxes.
	Note that space distributed by 'ruby-align' is unrelated to, and independent of,
	any space distributed due to justification.

	For [=inter-character=] annotations,
	this property can also affect the alignment of the box itself
	(see [[#inter-character-layout]]).
	It otherwise only affects the alignment of content within the box,
	not the size or position of the box itself.

	Values have the following meanings:
	<dl dfn-for=ruby-align dfn-type=value>
		<dt><dfn>start</dfn></dt>
		<dd>
			The ruby content is aligned with the start edge of its box.
			<div class="figure">
				<img width="145" height="91" src="images/ra-l.gif"
				     alt="Diagram of glyph layout in left aligned ruby when ruby text is shorter than base" >
				<img width="145" height="91"
				     alt="Diagram of glyph layout in left aligned ruby when ruby text is longer than base"
				     src="images/ra-l-rb.gif" >
				<p class="caption">''ruby-align/start'' ruby distribution
			</div>

			ISSUE: "Katatsuki ruby" (肩付きルビ) is close to,
			but not quite the same as,
			this ''ruby-align/start'' value.
			In particular,
			its behavior when overhanging its base
			can differ from start alignment
			depending on surrounding context,
			see <a href="https://www.w3.org/TR/jlreq/#positioning_of_monoruby_with_respect_to_base_characters">JLREQ</a>.
			Also, it's only ever used in vertical writing,
			and the JLTF considers it not particularly important,
			so it may not be worth the effort to make this value smart enough to deal with katatsuki ruby.
			If ''ruby-align/start'' is needed for some other purpose,
			we should keep it.
			Otherwise, maybe just drop it?
		</dd>

		<dt><dfn>center</dfn></dt>
		<dd>The ruby content is centered within its box.
			<div class="figure">
				<img width="145" height="91"
				     alt="Diagram of glyph layout in center aligned ruby when ruby text is shorter than base"
				     src="images/ra-c.gif" >
				<img width="145" height="91"
				     alt="Diagram of glyph layout in center aligned ruby when ruby text is longer than base"
				     src="images/ra-c-rb.gif" >
				<p class="caption">''ruby-align/center'' ruby distribution
			</div>
		</dd>

		<dt><dfn>space-between</dfn></dt>
		<dd>
			The ruby content expands as defined for normal text justification
			(as defined by 'text-justify'),
			except that if there are no [=justification opportunities=]
			the content is centered.
			<div class="figure">
				<img width="145" height="91"
				     alt="Diagram of glyph layout in distribute-letter aligned ruby when ruby text is shorter than base"
				     src="images/ra-dl.gif" >
				<img width="145" height="91"
				     alt="Diagram of glyph layout in distribute-letter aligned ruby when ruby text is longer than base"
				     src="images/ra-dl-rb.gif" >
				<p class="caption">''ruby-align/space-between'' ruby distribution
			</div>
		</dd>

		<dt><dfn>space-around</dfn></dt>
		<dd>
			As for ''ruby-align/space-between''
			except that there exists an extra [=justification opportunities=]
			whose space is distributed half before and half after the ruby content.

			<div class="figure">
				<img width="145" height="91"
				     alt="Diagram of glyph layout in auto aligned ruby when ruby text is shorter than base"
				     src="images/ra-ds.gif" >
				<img width="145" height="91"
				     alt="Diagram of glyph layout in auto aligned ruby when ruby text is longer than base"
				     src="images/ra-ds-rb.gif" >
				<p class="caption">''ruby-align/space-around'' ruby distribution
			</div>
		</dd>
	</dl>

<!--

	[=Justification opportunities=] are defined in [[!CSS-TEXT-3]]
	and controlled by the 'text-justify' property.
	For the purpose of 'ruby-align' specifically,
	the following additional requirements apply under ''text-justify: auto'':

	<ul>
		<li>
			Any [=typographic letter unit=] from the Han, Kana, or Hangul scripts
			is handled the same as under ''text-justify: inter-character''.
		<li>
			In [=ruby annotations=] only (?),
			any [=typographic letter unit=] from the Bopomofo script
			is handled the same as under ''text-justify: inter-word''.
		<li>
			In [=ruby annotations=] only (?),
			neither SPACE U+0020 nor NO-BREAK SPACE U+00A0
			provide a [=justification opportunity=].
	</ul>

	<div class="example">
		Make an example showing `text-justify: auto` vs `text-justify: inter-word` vs `text-justify: inter-character`.
	</div>

	Relevant issues:
		https://github.com/w3c/csswg-drafts/issues/1907 bopomofo
		https://github.com/w3c/csswg-drafts/issues/771 spaces/Latin
		https://github.com/w3c/jlreq/issues/184

-->

	<div class="example">
		The [[#default-ua-ruby|default UA style sheet]] applies
		''text-justify: ruby'' to [=ruby annotations=],
		defining [=justification opportunities=]
		between every adjacent pair of CJK [=characters=]
		but not between adjacent pairs of Latin or Bopomofo [=characters=].
		Thus, the ''space-around'' and ''space-between'' values
		will nevertheless result in Latin or Bopomofo characters centered:
		<div class="figure">
			<img width="145" height="91"
			     alt="Diagram of glyph layout in auto aligned ruby when halfwidth ruby text is shorter than base"
			     src="images/ra-c-h.gif" >
			<img width="145" height="91"
			     alt="Diagram of character layout in auto aligned ruby when ruby text is longer than narrow-width base"
			     src="images/ra-c-rb-h.gif" >
			<p class="caption">Non-CJK ruby text in ''ruby-align/space-around'' and ''ruby-align/space-between'' ruby distribution are centered
		</div>

		The distribution of space can be controlled via 'text-justify'. [[CSS-TEXT-3]]
	</div>

	Content in [=ruby bases=] and [=ruby annotations=],
	except those that span due to ''ruby-merge: merge'',
	is aligned within its box based on the value of 'ruby-align' on that box.
	Content in [=merged annotations=]
	is aligned within the [=ruby annotation container=]
	based on the value of 'ruby-align' on the [=annotations container=],
	ignoring the value of 'ruby-align' on the individual [=ruby annotations=].

	Issue: What if a [=merged annotation=] causes the [=ruby segment=] to be wider?
	Does it cause each base to grow as if it were spanning them, as currently specified?
	This does not allow e.g. centering the text in a multi-base base container
	when its merged annotation is longer.
	Instead, maybe we should allow ruby-merge to apply to base containers as well,
	but this would require us either to allow a single base to span multiple annotations
	(if the base is merged but some annotation levels are not),
	or to require that if the base is merged, then all annotation levels must be merged as well.

	The way content is aligned when 'ruby-merge' is ''ruby-merge/auto'' is up to the user agent,
	but must be identical to that of ''ruby-merge: separate''
	when all annotations fit over their respective bases.

<h3 id="ruby-text-decoration">
Ruby Text Decoration</h3>

	Text decoration does not propagate from the base text to the annotations.

	When text decoration is specified on an ancestor of the ruby,
	it is drawn across the entire content area of the ruby base container,
	including any extra space added on either side of the ruby base contents to accommodate long annotations.
	When text decoration is specified on a ruby base itself,
	this extra space is not decorated,
	similar to how a box's own padding is not decorated when text decoration is specified directly on that box. [[!CSS3-TEXT-DECOR]]

	Text decoration may be specified directly on ruby base containers
	and ruby annotation containers:
	in such cases it is propagated to all of the container's bases or annotations (respectively),
	and is also drawn between them for continuity.

	The positions of ruby annotations may be adjusted
	to avoid potential conflicts
	with overline and underline decorations applied to the base text.
	In the basic case of consistent font size and baseline alignment,
	an underline or overline is positioned
	between the [=base level=] and any annotations on that side.

	Issue: This section needs some clarification about
	drawing decorations between the content of adjacent bases/annotations.
	Depends on if those boxes are as wide as their [=column=] or not.

<h2 id="edge-effects">
Edge Effects</h2>

<h3 id="ruby-overhang">
Overhanging Ruby: the 'ruby-overhang' property</h3>

	<pre class="propdef">
	Name: ruby-overhang
	Value: auto | none
	Initial: auto
	Applies to: ruby annotation containers
	Inherited: yes
	Computed value: specified keyword
	Animation type: by computed value type
	</pre>

	The 'ruby-overhang' property controls whether [=ruby annotations=]
	may overlap adjacent text outside the [=ruby container=].
	Values have the following meanings:

	<dl dfn-type=value dfn-for=ruby-overhang>
		<dt><dfn>auto</dfn>
		<dd>
			When a [=ruby annotation container=] is longer than
			its corresponding [=ruby base container=],
			the [=ruby annotation container=] may
			partially overlap adjacent boxes.

			Whether, how much, and under which conditions to overhang
			are determined by the UA.

		<dt><dfn>none</dfn>
		<dd>
			A [=ruby annotation container=] is never allowed
			to extend past the [=ruby annotation container=].
	</dl>

	When [=ruby annotations=] are not allowed to overhang,
	the [=ruby container=] behaves like a traditional inline box,
	i.e. only its own contents are rendered within its boundaries
	and adjacent elements do not cross the box boundary:

	<div class="figure">
		<img src="images/ro-n.gif"
		     alt="Diagram showing the ruby boxes interacting with adjacent text">
		<p class="caption">Simple ruby whose text is not allowed to overhang adjacent text
	</div>

	However, if a [=ruby annotation container=] is allowed to overhang,
	neighbouring content may overlap the [=ruby container box=],
	allowing its [=ruby annotation=](s) to partially render over/under
	surrounding inline-level content.
	Overhang is only allowed to the extent
	that it does not cause collisions between
	the neighboring content
	and the ruby container’s [=annotation boxes=]
	or its overlapped [=base=]’s contents.

	<div class="figure">
		<img src="images/ro-a.gif"
		     alt="Diagram showing the ruby boxes interacting with adjacent text">
		<p class="caption">Simple ruby whose text is allowed to overhang adjacent text
	</div>

	Note: Whether [=ruby annotations=] related to a [=ruby base=]
	can overhang another [=ruby base=] is controlled by 'ruby-merge'.

	Typically,
	the alignment of the contents of the base or the annotation
	is not affected by overhanging behavior:
	alignment and space distribution (see 'ruby-align')
	is achieved the same way regardless of the overhang allowance,
	and is computed before the space available for overlap is determined.
	However, UAs may consider allowed overhang
	when determining space distribution and/or alignment of annotations and bases.

	Issue: I suspect overhanging interacts with alignment in some cases;
	might need to look into this later.

	<div class="example">
		The user agent may use [[JIS4051]] recommendation of
		using <a href=https://www.w3.org/TR/css-values-4/#ic>''0.5ic''</a> (half of a full-width character) in the annotation’s font
		as the maximum overhang length.
		Detailed rules for how ruby text can overhang adjacent characters
		for Japanese are described by [[JLREQ]].
	</div>

<h3 id="line-edge">
Line-edge Alignment</h3>

	When a [=ruby annotation box=] that is longer than its [=ruby base=]
	is at the start or end edge of a line,
	the user agent <em>may</em> force the side of the [=ruby annotation=] that touches the edge of the line
	to align to the corresponding edge of the base.
	This type of alignment is described by [[JLREQ]].

	This level of the specification does not provide a mechanism to control this behavior.

	<div class="figure">
		<img src="images/ra-le-l.gif"
		     alt="Diagram of glyph layout in line-edge aligned ruby when ruby text is shorter than base" >
		<img src="images/ra-le-r.gif"
		     alt="Diagram of glyph layout in line-edge aligned ruby when ruby text is longer than base" >
		<p class="caption">Line-edge alignment
	</div>

<!--
<h3 id="rubyover">
Ruby overhanging: the 'ruby-overhang' property</h3>

	<pre class="propdef">
	Name: ruby-overhang
	Value: auto | start | end | none
	Initial: none
	Applies to: the parent of elements with display: ruby-text
	Inherited: yes
	Percentages: N/A
	Computed value: as specified
	Animation type: discrete
	</pre>

	This property determines whether, and on which side,
	ruby text is allowed to partially overhang any adjacent text in addition to its own base,
	when the ruby text is wider than the ruby base.
	Note that ruby text is never allowed to overhang glyphs belonging to another ruby base.
	<span class="issue"><span class="issuehead">Issue:&nbsp;</span> This rule must be broken
	if we are to allow support for jukugo ruby.</span>
	Also the user agent is free to assume
	a maximum amount by which ruby text may overhang adjacent text.
	The user agent may use the [[JIS4051]] recommendation
	of using one ruby text character length as the maximum overhang length.
	Detailed rules for how ruby text can overhang adjacent characters for Japanese are described by [[JLREQ]].

	Possible values:
	<dl>
		<dt><strong>auto</strong></dt>
		<dd>
			The ruby text can overhang text adjacent to the base on either side.
			[[JLREQ]] and [[JIS4051]] specify the categories of characters
			that ruby text can overhang.
			The user agent is free to follow those recommendations
			or specify its own classes of characters to overhang.
			This is the initial value.
			<div class="figure">
				<img class="example" width="177" height="91"
				     alt="Diagram of glyph layout in overhanging ruby" src="images/ro-a.gif" >
				<b>Figure 4.3.1</b>: Ruby overhanging adjacent text
			</div>
		<dt><strong>start</strong></dt>
		<dd>
			The ruby text can only overhang the text that precedes it.
			That means, for example, that ruby cannot overhang text
			that is to the right of it in horizontal LTR layout,
			and it cannot overhang text that is below it in vertical-ideographic layout.
			<div class="figure">
				<img class="example" width="199" height="91"
				     alt="Diagram of glyph layout when ruby overhangs the preceding glyphs only"
				     src="images/ro-s.gif" >
				<b>Figure 4.3.2</b>: Ruby overhanging preceding text only
			</div>
		<dt><strong>end</strong></dt>
		<dd>
			The ruby text can only overhang the text that follows it.
			That means, for example, that ruby cannot overhang text
			that is to the left of it in horizontal LTR layout,
			and it cannot overhang text that is above it in vertical-ideographic layout.
			<div class="figure">
				<img class="example" width="198" height="91"
				     alt="Diagram of glyph layout when ruby overhangs the following characters only"
				     src="images/ro-e.gif" >
				<b>Figure 4.3.3</b>: Ruby overhanging following text only
			</div>
		<dt><strong>none</strong></dt>
		<dd>
			The ruby text cannot overhang any text adjacent to its base,
			only its own base.

			<div class="figure">
				<img class="example" width="220" height="91"
				     alt="Diagram of glyph layout in non-overhanging ruby"
				     src="images/ro-n.gif" >
				<b>Figure 4.3.4</b>: Ruby not allowed to overhang adjacent text
			</div>
	</dl>

<h3 id="rubyspan">
Ruby annotation spanning: the 'ruby-span' property</h3>

	<pre class="propdef">
	Name: ruby-span
	Value: attr(x) |  none
	Initial: none
	Applies to: elements with display: ruby-text
	Inherited: no
	Percentages: N/A
	Computed value: <<number>> (see prose)
	Animation type: not animatable
	</pre>

	This property controls the spanning behavior of annotation elements.

	Note: A XHTML user agent may also use the <samp>rbspan</samp> attribute
	to get the same effect.

	Possible values:

	<dl>
		<dt><strong>attr(x)</strong></dt>
		<dd>
			The value of attribute 'x' as a string value.
			The string value is evaluated as a &lt;number&gt;
			to determine the number of ruby base elements to be spanned by the annotation element.
			If the &lt;number&gt; is &#39;0&#39;,
			it is replaced by &#39;1&#39;.The &lt;number&gt; is the computed value.

		<dt>none</dt>
		<dd>
			No spanning. The computed value is &#39;1&#39;.
	</dl>

	The following example shows an XML example using the 'display' property values
	associated with the ruby structure and the 'ruby-span' property
	<pre class="xml">myruby       { display: ruby; }
	myrbc        { display: ruby-base-container; }
	myrb         { display: ruby-base; }
	myrtc.before { display: ruby-text-container; ruby-position: before}
	myrtc.after  { display: ruby-text-container; ruby-position: after}
	myrt         { display: ruby-text; ruby-span: attr(rbspan); }
	...
	&lt;myruby&gt;
		&lt;myrbc&gt;
			&lt;myrb&gt;10&lt;/myrb&gt;
			&lt;myrb&gt;31&lt;/myrb&gt;
			&lt;myrb&gt;2002&lt;/myrb&gt;
		&lt;/myrbc&gt;
		&lt;myrtc class=&quot;before&quot;&gt;
			&lt;myrt&gt;Month&lt;/myrt&gt;
			&lt;myrt&gt;Day&lt;/myrt&gt;
			&lt;myrt&gt;Year&lt;/myrt&gt;
		&lt;/myrtc&gt;
		&lt;myrtc class=&quot;after&quot;&gt;
			&lt;myrt rbspan=&quot;3&quot;&gt;Expiration Date&lt;/myrt&gt;
		&lt;/myrtc&gt;
	&lt;/myruby&gt;</pre>
-->

<h2 id="default-stylesheet" class="no-num">
Appendix A: Sample Style Sheets</h2>

	<em>This section is informative.</em>

<h3 id="default-ua-ruby" class="no-num">
<span class="secno">A.1</span> Default UA Style Sheet</h3>

	The following represents a default UA style sheet
	for rendering HTML and XHTML ruby markup as ruby layout:

	<pre highlight=css>
		ruby { display: ruby; }
		rp   { display: none; }
		rbc  { display: ruby-base-container; }
		rtc  { display: ruby-text-container; }
		rb   { display: ruby-base; white-space: nowrap; }
		rt   { display: ruby-text; }
		ruby, rb, rt, rbc, rtc { unicode-bidi: isolate; }

		rtc, rt {
			font-variant-east-asian: ruby;  /* See [[CSS-FONTS-3]] */
			text-justify: ruby;             /* See [[CSS-TEXT-4]] */
			text-emphasis: none;            /* See [[CSS-TEXT-DECOR-3]] */
			white-space: nowrap;
			line-height: 1; }

		rtc, :not(rtc) > rt {
			font-size: 50%; }
		rtc:lang(zh-TW), :not(rtc) > rt:lang(zh-TW),
		rtc:lang(zh-Hanb), :not(rtc) > rt:lang(zh-Hanb), {
			font-size: 30%; }               /* bopomofo */
	</pre>

	Note: Authors should not use the above rules:
	a UA that supports ruby layout should provide these by default.

	UAs implementing a user-controlled “minimum font size” feature
	should consider scaling that minimum down for ruby annotations.

<h3 id="default-inline" class="no-num">
<span class="secno">A.2</span> Inlining Ruby Annotations</h3>

	The following represents a sample style sheet
	for rendering HTML and XHTML ruby markup as inline annotations:

	<pre highlight=css>
		ruby, rb, rt, rbc, rtc, rp {
			display: inline; white-space: inherit;
			font: inherit; text-emphasis: inherit; }</pre>

<h3 id="default-parens" class="no-num">
<span class="secno">A.3</span> Generating Parentheses</h3>

	Unfortunately, because Selectors cannot match against text nodes,
	it's not possible with CSS to express rules that will automatically and correctly
	add parentheses to unparenthesized ruby annotations
	for all possible ruby markup patterns in HTML.
	(This is because HTML ruby allows implying the [=ruby base=] from raw text
	without a corresponding element.)

	However, these rules will add parentheses around each annotation sequence
	in cases where either <code>&lt;rb&gt;</code>
	or <code>&lt;rtc&gt;</code> is used rigorously:

	<pre highlight=css>
		/* Parens around &lt;rtc> */
		rtc::before { content: "（"; }
		rtc::after  { content: "）"; }

		/* Parens before first &lt;rt> not inside &lt;rtc> */
		rb  + rt::before,
		rtc + rt::before { content: "（"; }

		/* Parens after &lt;rt> not inside &lt;rtc> */
		rb ~ rt:last-child::after,
		rt + rb::before  { content: "）"; }
		rt + rtc::before { content: "）（"; }</pre>

	Alternatively, if it is known that a purely alternating style of markup is used
	(<code highlight=html>&lt;ruby>A&lt;rt>a&lt;/rt>B&lt;rt>b&lt;/rt>C&lt;rt>c&lt;/rt>&lt;ruby></code>)
	where there are no adjacent ruby annotations,
	the following rules will add parentheses around each annotation:

	<pre highlight=css>
		/* Parens around each &lt;rt> */
		rt::before { content: "（"; }
		rt::after  { content: "）"; }
	</pre>

<h2 id="glossary">
Glossary</h2>
	<dl>
		<dt id="g-bopomofo"><dfn noexport>Bopomofo</dfn> or <dfn noexport>Zhuyin Fuhao</dfn> (Chinese: <span lang=zh-Bopo>ㄅㄆㄇㄈ</span>, <span lang=zh-Hant>注音符號</span>, or <span lang=zh-Hans>注音符号</span>)
		<dd>
			<p>Characters and tone markings developed for use as phonetics in Chinese,
			especially standard Mandarin.
			These are often, but not exclusively, used for ruby annotations.

			<div class="figure">
				<img src="images/zhuyin-example.png"
				     alt="Bopomofo characters (in blue) run vertically along the right side of each Hanzi character in the horizontal text.">
				<p class="caption">Example of Bopomofo used as phonetic inter-character annotations in Chinese
			</div>

			<dfn>Bopomofo tone marks</dfn> are spacing characters that occur
			(in memory)
			at the end of each bopomofo syllable.
			They are typically displayed in a separate track
			to the right of or above the other bopomofo characters,
			and the position of the tone mark depends
			on the number of characters in the syllable.
			The neutral tone mark, however,
			is placed before (and in line with) the bopomofo, not alongside it.
			<!-- See Taiwanese requirements doc for EPUB at https://lists.w3.org/Archives/Public/www-archive/2020Apr/att-0005/EGLS_TW_eng.ppt -->

			Note: The user agent and font subsystem are responsible for
			ensuring the correct relative alignment and positioning of glyphs,
			including [=bopomofo tone marks=], when displaying text--
			whether the text occurs in ruby annotations or as normal inline content.
			Such glyph placement is not a function of CSS ruby layout.

			Bopomofo [=letters=] belong to the <code>Bopomofo</code> [=Unicode script=]
			(and are currently mapped in the U+3100–312F and U+31A0–31BF blocks);
			the [=Bopomofo tone marks=] are
			U+02C9 (ˉ), U+02CA (ˊ), U+02C7 (ˇ), U+02CB (ˋ), U+02EA (˪), U+02EB (˫), U+02D9 (˙).
			Collectively these are all considered <dfn export>Bopomofo characters</dfn>
			for the purpose of CSS.

		<dt id="g-hanja">Hanja (Korean: <span lang=ko>漢字</span>)
		<dd>
			Subset of the Korean writing system that utilizes ideographic
			characters borrowed or adapted from the Chinese writing system.
			Also see <a href="#g-kanji">Kanji</a>.

		<dt id="g-hiragana">Hiragana (Japanese: <span lang=ja>平仮名</span>)
		<dd>
			Japanese syllabic script, or character of that script.
			Rounded and cursive in appearance.
			Subset of the Japanese writing system,
			used together with kanji and katakana.
			In recent times,
			mostly used to write Japanese words
			when kanji are not available or appropriate,
			and word endings and particles.
			Also see <a href="#g-katakana">Katakana</a>.

		<dt id="g-ideogram">Ideograph
		<dd>
			A character that is used to represent an idea, word, or word component,
			in contrast to a character from an alphabetic or syllabic script.
			The most well-known ideographic script is used (with some variation)
			in East Asia (China, Japan, Korea,...).
		<dt id="g-kana">Kana (Japanese: <span lang=ja>仮名</span>)
		<dd>
			Collective term for hiragana and katakana.

		<dt id="g-kanji">Kanji (Japanese: <span lang=ja>漢字</span>)
		<dd>
			Japanese term for ideographs; ideographs used in Japanese.
			Subset of the Japanese writing system,
			used together with hiragana and katakana.
			Also see <a href="#g-hanja">Hanja</a>.

		<dt id="g-katakana">Katakana (Japanese: <span lang=ja>片仮名</span>)
		<dd>
			Japanese syllabic script, or character of that script.
			Angular in appearance.
			Subset of the Japanese writing system,
			used together with kanji and hiragana.
			In recent times, mainly used to write foreign words.
			Also see <a href="#g-hiragana">Hiragana</a>.
	</dl>

<h2 class=no-num id="acknowledgments">
Acknowledgments</h2>

	This specification would not have been possible without the help from:

	David Baron,
	Robin Berjon,
	Susanna Bowen,
	Stephen Deach,
	Martin Dürst,
	Hideki Hiura (<span lang="ja">樋浦 秀樹</span>),
	Masayasu Ishikawa (<span lang="ja">石川雅康</span>),
	Taichi Kawabata,
	Chris Pratley,
	Xidorn Quan,
	Takao Suzuki (<span lang="ja">鈴木 孝雄</span>),
	Frank Yung-Fong Tang,
	Chris Thrasher,
	Masafumi Yabe (<span lang="ja">家辺勝文</span>),
	Boris Zbarsky,
	Steve Zilles.

	Special thanks goes to the previous editors:
	Michel Suignard and Marcin Sawicki of Microsoft,
	and Richard Ishida of W3C.

<h2 class="no-num" id="changes">
Changes</h2>

	This section documents the changes since previous publications.

<h3 id="changes-20211202">
Changes since the 2 December 2021 WD</h3>

	<ul>
		<li>Made the computed-value adjustment of 'writing-mode' on [=inter-character annotations=]
			apply to the [=ruby annotation box=] rather than the [=ruby annotation container box=].
		<li>Added <code>zh-Hant</code> to rule applying ''font-size: 30%'' to [=ruby annotations=] in HTML.
		<li>Added <code>text-justify: ruby</code> to the UA default style sheet.
			(<a href="https://github.com/w3c/csswg-drafts/issues/771">Issue 771</a>
			 <a href="https://github.com/w3c/csswg-drafts/issues/779">Issue 779</a>)
	</ul>

<h3 id="changes-20200429">
Changes since the 29 April 2020 WD</h3>

	<ul>
		<li>Added ''ruby-position/alternate'' keyword to 'ruby-position'
			and made it the [=initial value=].
		<li>Renamed <css>collapse</css> value of 'ruby-merge' to ''ruby-merge/merge''.
			(<a href="https://github.com/w3c/csswg-drafts/issues/5004">Issue 5004</a>)
		<li>Defined ''visibility: collapse'' to explicitly [=hide=] an annotation
			the same way [=auto-hidden=] annotations are hidden.
			(<a href="https://github.com/w3c/csswg-drafts/issues/5927">Issue 5927</a>)
		<li>Specified more precisely which properties apply to the various ruby display types
			([[#box-style]])
			and defined ruby, ruby base, and ruby annotation boxes
			to behave the same as regular [=inline boxes=] except as otherwise specified.
			(<a href="https://github.com/w3c/csswg-drafts/issues/4935">Issue 4935</a>,
			<a href="https://github.com/w3c/csswg-drafts/issues/4936">Issue 4936</a>,
			<a href="https://github.com/w3c/csswg-drafts/issues/4976">Issue 4976</a>,
			<a href="https://github.com/w3c/csswg-drafts/issues/4979">Issue 4979</a>)
		<li>Substantially revamped [[#ruby-layout]] to more clearly define
			[=interlinear=] and [=inter-character=] ruby layout
			and their interaction with 'ruby-align'.
			[=Inter-character=] ruby is now based on [=inline block=] layout,
			and its interaction with [=interlinear=] ruby
			is also now well-defined.
			Inline-axis space distribution for [=interlinear=] ruby
			is now more precisely defined for spanning annotations
			(modeled on ''grid-template-columns/max-content'' grid tracks).
		<li>Defined handling of nested ruby
			by accounting for their base and annotation containers
			in the block-axis sizing of [=interlinear=] ruby.
			(<a href="https://github.com/w3c/csswg-drafts/issues/4986">Issue 4986</a>,
			<a href="https://github.com/w3c/csswg-drafts/issues/4980">Issue 4980</a>)
		<li>Specified more precisely how 'ruby-align' works.
		<li>Loosened requirement that ruby overhang not affect the alignment of ruby contents,
			added requirement that it not cause ruby content to collide with adjacent content.
		<li>Clarified interaction of bidi reordering and [=merged annotations=].
			([[#bidi]])
		<li>Tightened up normative prose throughout.
		<li>Improved [[#intro|introduction]], examples, and other informative text.
	</ul>

	Note: There remain many open issues, see <a href="https://drafts.csswg.org/css-ruby-1/issues-wd-2020">Disposition of Comments</a>
	and the <a href="https://github.com/w3c/csswg-drafts/issues?q=is%3Aissue+label%3Acss-ruby-1">newer issues</a>
	tracked in GitHub.

<h3 id="changes-20140805">
Changes since the 5 August 2014 WD</h3>

	<ul>
		<li>Add back ''ruby-overhang: auto | none'' for basic control over ruby overhang behavior.
		<li>Harmonize inlinification with the <a href="https://www.w3.org/TR/css-display-3/">CSS Display Module</a>.
		<li>Allow UA to shift ruby/emphasis marks if they conflict with underlines/overlines.
		<li>Disable auto-hiding when the computed value of 'ruby-merge' is <code>collapse</code>.
		<li>Tweak the <a href="#default-stylesheet">default style sheet</a>.
		<li>Add section defining interaction with <a href="#ruby-text-decoration">text decoration</a>.
		<li>Defer the <css>right</css> and <css>left</css> values of 'ruby-position' to the next level.
		<li>Change ruby [=pairing=] rules to only apply spanning on anonymous annotations (i.e. content directly contained by an <{rtc}>).
		<li>Pair excess bases / annotations with auto-generated empty anonymous bases / annotations.
		<li>
			Apply 'ruby-position' to ''::first-line''.
			(<a href="https://github.com/w3c/csswg-drafts/issues/2998">Issue 2998</a>)
		<li>Clarify containing block of ruby boxes and contents is, as in the case of other inline boxes, the nearest block container.
		<li>Clarify handling of misparented internal table elements.
		<li>Trim leading/trailing white space in ruby containers, base base containers, and annotation containers to prevent it from interfering with pairing.
		<li>Define layout effect of empty base and annotation containers.
		<li>Disable margins, padding, and borders on ruby base containers and ruby annotation containers (but not on ruby bases and ruby annotations).
	</ul>

<h3 id="changes-20130919">
Changes since the 19 September 2013 WD</h3>

	<ul>
		<li>
			Rewrite anonymous box generation rules and white space handling rules,
			defined specialized [=pairing=] of anonymous white space boxes.
		<li>
			Take nested ruby handling out of [=pairing=].
			(Will be handling it via sizing/layout.)
		<li>
			Define bidi layout of ruby structures.
	</ul>

<h3 id="changes-20110630">
Changes since the 30 June 2011 WD</h3>

	<dl>
		<dt>Remove <code>ruby-span</code> and mentions of <code>rbspan</code>.

		<dd>
			Explicit spanning is not used in HTML ruby in favor of implicit spanning.
			This can't handle some pathological double-sided spanning cases,
			but there seems to be no requirement for these at the moment.
			(For implementations that support full complex XHTML Ruby,
			they can imply spanning from the markup the same magic way
			that we handle cell spanning from tables.
			It doesn't seem necessary to include controls this in Level 1.)

		<dt>Defer <code>ruby-overhang</code> and <code>ruby-align: line-end</code> to Level 2.

		<dd>
			It's somewhat complicated, advanced feature.
			Proposal is to make this behavior UA-defined and provide some examples of acceptable options.

		<dt>Close issue requesting <code>display: rp</code>: use <code>display: none</code>.

		<dd>
			The Internationalization WG added an issue
			requesting a display value for <{rp}> elements.
			They're supposed to be hidden when <{ruby}> is displayed as ruby.
			But this is easily accomplished already with <code>display: none</code>.

		<dt>Change 'ruby-position' values to match 'text-emphasis-position'.

		<dd>
			Other than ''inter-character'', which we need to keep,
			it makes more sense to align ruby positions with 'text-emphasis-position',
			which can correctly handle various combinations of horizontal/vertical preferences.

		<dt>Remove unused values of 'ruby-align'.

		<dd>
			<css>left</css>, <css>right</css>, and <css>end</css> are not needed.

		<dt>
			Replace <css>auto</css>, <css>distribute-letter</css>, and <css>distribute-space</css>
			from 'ruby-align' with ''space-between'' and ''space-around''.

		<dd>
			The <css>auto</css> value relied on inspecting content to determine behavior;
			this can be avoided by just using ''space-around'' with standard justification rules
			(which allow spacing between CJK but not between Latin).
			Replaced <css>distribute-letter</css> and <css>distribute-space</css>
			with ''space-between'' and ''space-around''
			for consistency with distribution keywords in [[CSS-FLEXBOX-1]] and [[CSS-ALIGN-3]]
			and to avoid any links to the definition of <code>text-justify: distribute</code>.

		<dt>Added 'ruby-merge' property to control jukugo rendering.

		<dd>
			This is a stylistic effect, not a structural one;
			the previous model assumed that it was structural
			and suggested handling it by changing markup. :(

		<dt>Remove <css>inline</css> from 'ruby-position'.

		<dd>
			This is do-able via <code>display: inline</code>
			on all the ruby-related elements,
			see <a href="#default-inline">Appendix A</a>.

		<dt>Added <a href="#default-stylesheet">Default Style</a> rules

		<dd>As requested by Internationalization WG.

		<dt>Wrote anonymous box generation rules

		<dd>
			And defined [=pairing=] of bases and annotations.
			Should now handle all the crazy proposed permutations of HTML ruby markup.

		<dt>Defined layout of ruby

		<dd>
			Defined in detail space distribution, white space handling,
			line breaking, line stacking, etc.
			Open issue left for bidi.
	</dl>

<h2 class=no-num id=privacy>Privacy Considerations</h2>

No new privacy considerations have been reported on this specification.

<h2 class=no-num id=security>Security Considerations</h2>

No new security considerations have been reported on this specification.

<pre class=biblio>
{
	"QA-RUBY": {
		"href": "https://www.w3.org/International/questions/qa-ruby",
		"title": "What is ruby?",
		"publisher": "W3C",
		"authors": [ "Richard Ishida" ]
	}
}
</pre>
